Guest User

Untitled

a guest
Jun 23rd, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  1. function forgotten_password(){
  2.         if(!empty($this->data)){
  3.             $conditions['User.email'] = $this->data['User']['email'];
  4.             $user = $this->User->find($conditions);
  5.             if(!empty($user)){
  6.                 $newPass = substr(hash('md5', uniqid()), rand(0, 24), 8);
  7.                 $this->Email->charset = 'utf-8';
  8.                 $this->Email->xMailer = Configure::read('App.name').' Mail Component';
  9.                 $this->Email->sendAs = 'html';
  10.                 $this->Email->delivery = 'mail';
  11.                 $this->Email->to = $user['User']['email'];
  12.                 $this->Email->from = Configure::read('App.email_from');
  13.                 $this->Email->subject = Configure::read('App.name').': Password changed';
  14.                 $content = array(
  15.                     'name'=>$user['User']['name'].' '.$user['User']['surname'].' '.$user['User']['lastname'],
  16.                     'email'=>($user['User']['email']!=$user['User']['username']?$user['User']['username']:$user['User']['email']),
  17.                     'passwd'=>$newPass
  18.                 );
  19.                 $this->set('contentData', $content);
  20.                 if ($this->Email->send($content, 'password')){
  21.                     $this->Session->setFlash(__('Password sent successfully', true));
  22.                     $this->User->save(array('id'=>$user['User']['id'], 'passwd'=>$newPass));
  23.                     $this->redirect('/');
  24.                 }else{
  25.                     $this->Session->setFlash(__('sending problem', true));
  26.                 }
  27.             }else{
  28.                 $this->Session->setFlash(__('Неизвестен потребител или грешен E-mail!', true));
  29.             }
  30.         }
  31.     }
Add Comment
Please, Sign In to add comment