Auth->user('id')) { $this->redirect('/users/view'); } else { //try to login user only if it's post request (when form is submited) if ($this->request->is('post')) { //that how we login if($this->Auth->login()){ $this->set('Auth', $this->AuthUser); $this->redirect('/users/view'); } } } } function admin_login(){ $this->redirect('/users/login'); exit; } function logout(){ //That thing is working correct //$this->Auth->logout(); return $this->redirect($this->Auth->logout()); } function beforeFilter(){ if(in_array($this->request->action, array('admin_add', 'admin_edit', 'create_account', 'change_password')) ) { $this->Auth->authenticate = $this->User; } // $this->Auth->allow($this->_getAllowedActions()); parent::beforeFilter(); $this->set('title_for_layout', __('Аккаунт пользователя')); } function create_account(){ //$this->layout = 'ajax'; $this->set('title_for_layout', __('Регистрация')); $this->set('body_class', 'registration'); $this->Account->contain(); if ($this->request->is('post')){ $this->request->data["Group"]["Group"]= GroupsUser::Users; $this->User->create(); //$this->User->registering = true; //debug($this->request->data); if ($this->Recaptcha->verify()) { if ($this->User->save($this->request->data)){ //$user_id = $this->User->getInsertId(); //$account = $this->Account->createAccount($user_id); //debug($account); $this->Session->setFlash(sprintf(__('Благодарим за регистрацию'))); $id = $this->User->id; $this->request->data['User'] = array_merge( $this->request->data['User'], array('id' => $id) ); unset($this->request->data['User']['password']); $account = $this->Account->createAccount($id); $this->Auth->login($this->request->data['User']); /*if($this->Auth->login()){ $this->log('Loged in...', LOG_DEBUG); }else{ $this->log('Not loged in...', LOG_DEBUG); }*/ $this->AuthUser = $this->Auth->user(); $this->set('Auth', $this->AuthUser); if ($this->sendEmail('accounts_create', array( 'to' => $this->request->data['User']['email'], 'subject' => __('Спасибо за регистрацию').' '. Configure::read('CMS.DomainName'), ))) { $this->Session->setFlash(sprintf(__('Вам послано письмо о регистрации'))); } else { $this->Session->setFlash(sprintf(__('Ошибка отправки письма'))); } //TODO2 Сделать капчу recapcha //TODO3 Перейти в личний кабинет //debug($this->request->data); //$this->redirect('/' . Configure::read('Config.language') . '/users/view/'); // //$url = $this->Session->read('Auth.redirect'); //$this->redirect($url); $this->redirect('/users/view/'); } else{ $this->Session->setFlash(sprintf(__('Регистрация не удалась')), 'flashtop'); } } else { // display the raw API error $this->Session->setFlash($this->Recaptcha->error); } } } function change_password(){ $this->set('title_for_layout', __('Изменение пароля')); $this->User->contain(); $user = $this->User->findById($this->Auth->user('id')); if ($user && /*isset($this->request->data)*/$this->request->is('post')){ if($user['User']['password'] == Security::hash($this->request->data['User']['oldpassword'], null, true)) { debug($this->request->data); $user['User']['password'] = $this->request->data['User']['password']; $user['User']['passwordconfirm'] = $this->request->data['User']['passwordconfirm']; $saved = $this->User->save($user); if ($saved){ $this->Session->setFlash(sprintf(__('Пароль сохранен'))); $this->redirect('/users/view'); } else{ $this->Session->setFlash(sprintf(__('Пароль не сохранен'))); } } else $this->Session->setFlash(sprintf(__('Неверный текущий пароль')), 'flashtop'); } } function change_info(){ $this->set('title_for_layout', __('Изменение информации пользователя')); $this->User->contain(); $user = $this->User->findById($this->Auth->user('id')); if ($user && /*isset($this->request->data)*/$this->request->is('post')){ //debug($this->request->data); $user=$this->request->data; unset($user['User']['password']); $this->User->save($user); } $regions = $this->User->Region->find('list'); $this->set('regions',$regions); $this->request->data = $user; } function recover_password(){ $this->set('title_for_layout', __('Восстановления пароля')); if (!empty($this->request->data)) { if (Validation::email($this->request->data['User']['email'])) { // ok, valid e-mail $this->User->contain(); $user = $this->User->find('first', array('conditions' => array('User.email' => $this->request->data['User']['email']))); // ok, user found if ($user) { // generate and save new password $new_password = $this->User->generatePassword(); $this->User->id = $user['User']['id']; $this->User->saveField('password', $new_password); // and send it as plain text to user's e-mail $this->set('username', $user['User']['username']); $this->set('new_password', $new_password); $this->set('Auth', $this->AuthUser); if ($this->sendEmail('accounts_recover_password', array( 'to' => $this->request->data['User']['email'], 'subject' => __('Your new password for '). Configure::read('CMS.DomainName'), ))) $this->set('success', 1); } else{ $this->User->invalidate('email', __('Этот емейл не найден в базе')); } $this->set('email', $this->request->data['User']['email']); } else { $this->User->invalidate('email', __('Вы ввели неверный имейл')); } } } function view() { $this->set('Auth', $this->Auth->user()); $this->set('user', $user=$this->User->find('first', array('conditions'=>array('User.id'=>$this->Auth->user('id'))))); foreach ($user['Group'] as $used){ if ($used['name']=='Accounter'){ return $this->redirect(array('controller' => 'accountants', 'action' => 'index')); } } } function edit($id = null) { if (!$id && empty($this->request->data)) { $this->Session->setFlash(sprintf(__('Ошибочный %s'), 'user')); return $this->redirect(array('action' => 'index')); } if (!empty($this->request->data)) { if ($this->User->save($this->request->data)) { $this->Session->setFlash(sprintf(__('%s был сохранен'), 'user')); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(sprintf(__('%s не сохранен. Попробуйте снова'), 'user')); } } if (empty($this->request->data)) { $this->request->data = $this->User->read(null, $id); } $regions = $this->User->Region->find('list'); $groups = $this->User->Group->find('list'); $this->set(compact('regions', 'groups')); } function admin_index() { $this->User->contain(); $this->paginate = array( 'contain' => array() ); $this->set('users', $this->paginate('User')); } function admin_customers() { $this->paginate = array( 'conditions' => array('GroupsUser.group_id' => 2), 'contain' => array('GroupsUser'), 'order' => 'User.id DESC' ); $users = $this->paginate('User'); $this->set('users', $users); //debug($users); } function admin_view($id = null) { if (!$id) { $this->Session->setFlash(sprintf(__('Invalid %s'), 'user')); return $this->redirect(array('action' => 'index')); } $this->set('user', $this->User->read(null, $id)); } function admin_add() { if (!empty($this->request->data)) { $this->User->create(); if ($this->User->save($this->request->data)) { $this->Session->setFlash(sprintf(__('The %s has been saved'), 'user')); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(sprintf(__('The %s could not be saved. Please, try again.'), 'user')); } } $regions = $this->User->Region->find('list'); $groups = $this->User->Group->find('list'); $this->set(compact('regions', 'groups')); } function admin_edit($id = null) { if (!$id && empty($this->request->data)) { $this->Session->setFlash(sprintf(__('Invalid %s'), 'user')); return $this->redirect(array('action' => 'index')); } if (!empty($this->request->data)) { if ($this->User->save($this->request->data)) { $this->Session->setFlash(sprintf(__('The %s has been saved'), 'user')); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(sprintf(__('The %s could not be saved. Please, try again.'), 'user')); } } if (empty($this->request->data)) { $this->request->data = $this->User->read(null, $id); } $regions = $this->User->Region->find('list'); $groups = $this->User->Group->find('list'); $this->set(compact('regions', 'groups')); } function admin_delete($id = null) { if (!$id) { $this->Session->setFlash(sprintf(__('Invalid id for %s'), 'user')); return $this->redirect(array('action'=>'index')); } if ($this->User->delete($id)) { $this->Session->setFlash(sprintf(__('%s deleted'), 'User')); return $this->redirect(array('action'=>'index')); } $this->Session->setFlash(sprintf(__('%s was not deleted'), 'User')); return $this->redirect(array('action' => 'index')); } } [/] Ваш проводник в мире обучения Html->link(__('Продукты'), array('controller' => 'versions', 'action' => 'index'), array('class' => 'page_item'));?> Html->link(__('Как купить'), array('controller' => 'staticpages', 'action' => 'view','buy'), array('class' => 'page_item'));?> Html->link(__('О нас'), array('controller' => 'staticpages', 'action' => 'view', 'about-us'), array('class' => 'page_item'));?> Html->link(__('Обратная связь'), array('controller' => 'feedbacks', 'action' => 'add'), array('class' => 'page_item', 'rel' => 'nofollow'));?> element('user_menu');?> Not Found Error: The requested address '/users/login' was not found on this server. Html->link(__('Продукты'), array('controller' => 'versions', 'action' => 'index'));?> Html->link(__('Как купить'), array('controller' => 'staticpages', 'action' => 'view', 'buy'));?> Html->link(__('Публичная оферта'), array('controller' => 'staticpages', 'action' => 'view', 'offerte'));?> Html->link(__('Обратная связь'), array('controller' => 'feedbacks', 'action' => 'add'));?> Html->link(__('FAQ'), array('controller' => 'faqs', 'action' => 'index'));?> Html->link(__('Контакты'), array('controller' => 'staticpages', 'action' => 'view', 'contacts'));?> Edusoft 2010-2013. Все права защищены.