function remember()
 {
     // check the email address given
     // if true send an email address with confirmation link
     // then return back to change password page.
     // then return to login page.
     $pbinput = Input::all();
     $pbemail = Input::get('email');
     $pbrules = array('email' => 'required|email');
     $pbvalidator = Validator::make($pbinput, $pbrules);
     if ($pbvalidator->passes()) {
         if (User::where('email', '=', $pbemail)->count() == 1) {
             /**
              * Goto the mail and database now...
              * 
              */
             $confirmation_code = str_random(30);
             $pbuser = User::where('email', '=', $pbemail)->first();
             $pbuserid = $pbuser->id;
             // goto the database...
             $forgotpassword = new Forgotpassword();
             $forgotpassword->user_id = $pbuserid;
             $forgotpassword->confirmed = 0;
             $forgotpassword->confirmation_code = $confirmation_code;
             $forgotpassword->save();
             $confirmation_code = array('confirmation_code' => $confirmation_code);
             Mail::send('emails.resetpassword', $confirmation_code, function ($message) {
                 $pbemail = Input::get('email');
                 $pb_user_email = $pbemail;
                 $message->from('*****@*****.**');
                 $message->to($pbemail)->subject('Password Reset Confirmation ');
             });
         } else {
             return Redirect::to('/forgotpassword')->with(array('message' => 'This email does not exits in our records.'));
         }
         return Redirect::to('/forgotpassword')->with(array('welcome_back' => 'Success, An email has been sent.'));
     } else {
         return Redirect::to('/forgotpassword')->with(array('message' => 'Email is required.'));
     }
 }
 public function check($confirmation_code)
 {
     if ($confirmed_code = Forgotpassword::where('confirmation_code', '=', $confirmation_code)->first()) {
         // delete the row of information.
         $user_id = $confirmed_code->user_id;
         // hash the email_id to prevent hacks
         Session::put('email_id', $user_id);
         Forgotpassword::where('user_id', '=', $user_id)->delete();
         return Redirect::to('/passwordreset')->with(array('welcome_back' => 'You have been confirmed please reset your password.', 'email_id' => $user_id));
         //return Redirect::to('login')->with(array('confirmed'=>'true','send_to'=>'chooseaccount'));
     } else {
         return Redirect::to('/forgotpassword')->with(array('message' => 'The verification link is expired or not correct. <a href="http://popibay.com/register">Register</a>'));
     }
 }
Пример #3
0
 public function run()
 {
     $model = new Forgotpassword();
     if (isset($_POST['Forgotpassword'])) {
         $model->attributes = $_POST['Forgotpassword'];
         if ($model->validate() && $model->emailregistered()) {
             $newpwd = $model->resetpwd();
             $body = 'Your new password:'******'Your new password at MusicDream';
             require_once Yii::getPathOfAlias('application') . '/components/functions.php';
             if (!mailer_mail($model->email, $subject, $body)) {
                 $contactMsg = 'Error.';
             } else {
                 $contactMsg = '您的密码已经发送到信箱,请注意查收。';
             }
             Yii::app()->user->setFlash('forgotpassword', $contactMsg);
             $this->refresh();
         } else {
             $model->addError('email', 'Email 不存在');
         }
     }
     $this->render('forgotpassword', array('model' => $model));
 }