4
0

apiController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * This controller manage API-related features.
  4. */
  5. class FreshRSS_api_Controller extends Minz_ActionController {
  6. /**
  7. * This action updates the user API password.
  8. *
  9. * Parameter is:
  10. * - apiPasswordPlain: the new user password
  11. */
  12. public function updatePasswordAction() {
  13. if (!FreshRSS_Auth::hasAccess()) {
  14. Minz_Error::error(403);
  15. }
  16. $return_url = array('c' => 'user', 'a' => 'profile');
  17. if (!Minz_Request::isPost()) {
  18. Minz_Request::forward($return_url, true);
  19. }
  20. $apiPasswordPlain = Minz_Request::param('apiPasswordPlain', '', true);
  21. if ($apiPasswordPlain == '') {
  22. Minz_Request::forward($return_url, true);
  23. }
  24. $username = Minz_Session::param('currentUser');
  25. $userConfig = FreshRSS_Context::$user_conf;
  26. $apiPasswordHash = FreshRSS_password_Util::hash($apiPasswordPlain);
  27. $userConfig->apiPasswordHash = $apiPasswordHash;
  28. $feverKey = FreshRSS_fever_Util::updateKey($username, $apiPasswordPlain);
  29. if (!$feverKey) {
  30. Minz_Request::bad(_t('feedback.api.password.failed'), $return_url);
  31. }
  32. $userConfig->feverKey = $feverKey;
  33. if ($userConfig->save()) {
  34. Minz_Request::good(_t('feedback.api.password.updated'), $return_url);
  35. } else {
  36. Minz_Request::bad(_t('feedback.api.password.failed'), $return_url);
  37. }
  38. }
  39. }