public function actionForgotPassword() { $email = $this->_request->getParam('email'); $refferer = $this->_request->getParam('referrer'); $objUserModel = new \models\Users(); $useRow = \R::findOne('users', 'email=:e', array(':e' => $email)); if ($useRow) { //generate token to reset password $token = $objUserModel->generateToken(); $useRow->token = $token; \R::store($useRow); // send mail in reset password link $resetUrl = $this->_serverinfo->getScheme() . "://" . $this->_serverinfo->getHost() . "/users/reset-password/?token={$token}&r={$refferer}"; $objMailer = new \mailer\Appmailer(); $subject = 'Reset Cimba Password'; $message = array('salutation_message' => "Dear {$useRow->first_name} {$useRow->last_name}", 'greeting_message' => 'Please click on the below link to reset your password on cimba', 'message_content' => array("<a href='{$resetUrl}'>{$resetUrl}</a>")); $objMailer->send($subject, $email, $message); $this->_response->renderJson(array('message' => "Please check your mail")); } else { $this->_response->renderJson(array('message' => "This email does not exists in our records."), 401); } }
/** * Function to insert user * @param array $userData Data of the user to be inserted in array format * @return int|boolean * **/ public function insert(array $userData) { $userRow = $userRow = \R::findOne($this->_name, 'user_name = :un OR email = :em', array(":un" => $userData['username'], ":em" => $userData['email'])); if ($userRow) { return self::EMAIL_ALREADY_EXISTS; // email already exixts } else { $password = $this->_generatePassword(); $salt = $this->_generateSalt(); $firstName = $userData['first_name']; $lastName = $userData['last_name']; $email = $userData['email']; $row = $this->_redBeans->dispense($this->_name); $row->user_name = $userData['username']; $row->email = $email; $row->first_name = $firstName; $row->last_name = $lastName; $row->password = md5($password . $salt); $row->salt = $salt; $row->pwd_exp_time = date('Y-m-d H:i:s', time() + 90 * 24 * 60 * 60); $row->date_registered = date('Y-m-d H:i:s'); $userId = $this->_redBeans->store($row); // send mail if ($userId) { // send email $objMailer = new \mailer\Appmailer(); $subject = 'Cimba User Registeration'; $message = array('greeting_message' => 'You are successfully registered on cimba.Please login with following details', 'salutation_message' => "Dear {$firstName} {$lastName}", 'message_content' => array('Email:' . $email, 'password:' . $password)); $objMailer->send($subject, $email, $message); } return $userId; } return false; }