Exemplo n.º 1
0
 public function init()
 {
     parent::init();
     // Verify we're on the correct database
     //print_r(coreConfig::get('database_connection'));exit;
     $connectionInfo = coreConfig::get('database_connection');
     $this->verbose("Using database: %s", $connectionInfo['database']);
     $username = trim($this->getOption('u'));
     $raw_password = trim($this->getOption('p'));
     if (empty($username) || empty($raw_password)) {
         $this->throwError('Username or password is empty.');
     }
     $userid = UsersPeer::getUserId($username);
     if (false === $userid) {
         $this->throwError('User named "%s" not found.', $username);
     }
     $this->verbose("Userid: %s", $userid);
     $this->verbose("Set password to: %s", $raw_password);
     $this->updateUser($userid, array('raw_password' => $raw_password));
     // only with linked PunBB forum
     if ($this->args->flag('forum')) {
         if (coreConfig::get('app_path_to_punbb') !== null) {
             PunBBUsersPeer::setPassword($username, $raw_password);
         } else {
             $this->throwError('Forum password: "******" is not defined in environment "%s"', CORE_ENVIRONMENT);
         }
     }
     $this->verbose('Success!');
 }
Exemplo n.º 2
0
 /**
  * Sends email to new members to confirm account details.
  * 
  */
 public function sendNewAccountConfirmation($userAddress, $userName, $rawPassword)
 {
     $from = coreConfig::get('app_email_robot');
     $this->setFrom($from['email'], isset($from['name']) ? $from['name'] : '');
     $this->addTo($userAddress, $userName);
     $this->setSubject('Welcome to Reviewing the Kanji');
     $this->setPriority(1);
     $forum_uid = coreConfig::get('app_path_to_punbb') !== null ? PunBBUsersPeer::getForumUID($userName) : false;
     $body = $this->renderTemplate('newAccountConfirmation', array('username' => $userName, 'password' => $rawPassword, 'email' => $userAddress, 'forum_uid' => $forum_uid));
     $this->setBodyText($body);
     $this->send();
 }
Exemplo n.º 3
0
 public function executeIndex($request)
 {
     $username = $request->getParameter('username');
     if (!$username) {
         if ($this->getUser()->isAuthenticated()) {
             $username = $this->getUser()->getUserName();
         } else {
             // if unauthenticated user checks his (bookmarked?) profile, go to login and back
             $url = $this->getController()->genUrl('profile/index', true);
             $this->getUser()->redirectToLogin(array('referer' => $url));
         }
     }
     if ($user = UsersPeer::getUser($username)) {
         $this->user = $user;
         $this->self_account = $user['username'] == $this->getUser()->getUserName();
         $this->kanji_count = ReviewsPeer::getReviewedFlashcardCount($user['userid']);
         $this->total_reviews = ReviewsPeer::getTotalReviews($user['userid']);
         $this->forum_uid = coreConfig::get('app_path_to_punbb') !== null ? PunBBUsersPeer::getInstance()->getForumUID($username) : false;
         return coreView::SUCCESS;
     }
     return coreView::ERROR;
 }
Exemplo n.º 4
0
 /**
  * Change Password.
  *
  * Update the user's password on the RevTK site AND the corresponding PunBB forum account.
  *   
  */
 public function executePassword($request)
 {
     if ($request->getMethod() != coreRequest::POST) {
         return coreView::SUCCESS;
     }
     // handle the form submission
     $validator = new coreValidator($this->getActionName());
     if ($validator->validate($request->getParameterHolder()->getAll())) {
         // verify old password
         $oldpassword = trim($request->getParameter('oldpassword'));
         $user = $this->getUser()->getUserDetails();
         if ($user && $this->getUser()->getSaltyHashedPassword($oldpassword) == $user['password']) {
             // proceed with password update
             $new_raw_password = trim($request->getParameter('newpassword'));
             $user = $this->getUser()->getUserDetails();
             // update the password on main site and forum
             $this->getUser()->changePassword($user['username'], $new_raw_password);
             // save username before signing out
             $this->username = $this->getUser()->getUserName();
             // log out user (sign out, clear cookie, clear punbb cookie(not on staging website))
             $this->getUser()->signOut();
             $this->getUser()->clearRememberMeCookie();
             if (coreContext::getInstance()->getConfiguration()->getEnvironment() !== 'staging' && coreConfig::get('app_path_to_punbb') !== null) {
                 PunBBUsersPeer::signOut();
             }
             try {
                 // send email confirmation
                 $mailer = new rtkMail();
                 $mailer->sendUpdatePasswordConfirmation($user['email'], $user['username'], $new_raw_password);
             } catch (coreException $e) {
                 $request->setError('mail_error', 'Oops, we tried sending you a confirmation email but the mail server didn\'t respond. Your password has been updated though!');
             }
             return 'Done';
         } else {
             $request->setError('login_invalid', "Old password doesn't match.");
         }
     }
     // clear the password fields (avoid input mistakes)
     $request->setParameter('oldpassword', '');
     $request->setParameter('newpassword', '');
     $request->setParameter('newpassword2', '');
 }
Exemplo n.º 5
0
 /**
  * Update the user password in the main site and forum databases.
  * 
  * @param string $user
  * @param string $raw_password
  */
 public function changePassword($username, $raw_password)
 {
     $user_id = UsersPeer::getUserId($username);
     $columns = array('raw_password' => $raw_password);
     UsersPeer::updateUser($user_id, $columns);
     // set new password on forum account (not in staging)
     if (coreContext::getInstance()->getConfiguration()->getEnvironment() !== 'staging') {
         // only with linked PunBB forum
         if (coreConfig::get('app_path_to_punbb') !== null) {
             PunBBUsersPeer::updateUser($username, $columns);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Sign Out.
  * 
  * @return 
  */
 public function executeLogout($request)
 {
     $this->getUser()->signOut();
     // clear the rememberme cookie
     $this->getUser()->clearRememberMeCookie();
     // clear the PunBB cookie (not on the test website)
     if (coreContext::getInstance()->getConfiguration()->getEnvironment() !== 'staging' && coreConfig::get('app_path_to_punbb') !== null) {
         PunBBUsersPeer::signOut();
     }
     return $this->redirect('@homepage');
 }
Exemplo n.º 7
0
 /**
  * Update the user password in the main site and forum databases.
  * 
  * @param object $user
  * @param object $raw_password
  */
 public function changePassword($username, $raw_password)
 {
     // hash password for database
     $hashedPassword = $this->getSaltyHashedPassword($raw_password);
     // set new user password
     $user_id = UsersPeer::getUserId($username);
     UsersPeer::setPassword($user_id, $hashedPassword);
     // set new password on forum account (not in staging)
     if (coreContext::getInstance()->getConfiguration()->getEnvironment() !== 'staging') {
         // only with linked PunBB forum
         if (coreConfig::get('app_path_to_punbb') !== null) {
             PunBBUsersPeer::setPassword($username, $raw_password);
         }
     }
 }