Beispiel #1
0
 public function action_reset_complete()
 {
     if ($this->request->post() != null) {
         try {
             // Find the user using the user email address
             $user = Sentry::getUserProvider()->findByLogin($this->request->post('email'));
             // Get the password reset code
             $resetCode = $user->getResetPasswordCode();
             Hint::set(Hint::SUCCESS, 'Your reset token is: "' . $resetCode);
             //everything went successful, send the user somewhere else
             $this->redirect(Route::url('S4K.users.reset', null, true));
             // @todo normally you wouldn't redirect here, but rather show a page conforming the code was sent
             // @todo Now you can send this code to your user via email for example.
         } catch (Cartalyst\Sentry\Users\UserNotFoundException $e) {
             Hint::set(Hint::ERROR, 'There\'s no user with that login credential.');
         }
         //No success trying to request a reset password token, show the form again with the errors
         $this->_tpl->hints = Hint::render(null, true, 's4k/hint');
         $this->action_reset();
     } else {
         // no post request made, send back
         $this->redirect(Route::url('S4K.users.reset', null, true));
     }
 }
Beispiel #2
0
 public function action_edit_complete()
 {
     $id = $this->request->param('id');
     try {
         $group = Sentry::getGroupProvider()->findById($id);
         if ($this->request->post() != null) {
             try {
                 $post = $this->request->post();
                 //set all posted permissions to 1
                 if (array_key_exists('permissions', $post) && count($post['permissions'] > 0)) {
                     $list = array();
                     foreach ($post['permissions'] as $key) {
                         $list[$key] = 1;
                     }
                     $post['permissions'] = $list;
                 }
                 //save the group
                 $group->values($post)->save();
                 //set a success message an redirect to the management page
                 Hint::set(Hint::SUCCESS, 'You\'ve successfully updated group "' . $group->name . '"');
                 $this->redirect(Route::url('S4K.groups', null, true));
             } catch (ORM_Validation_Exception $e) {
                 //Make hints out of the errors
                 foreach ($e->errors('model') as $error) {
                     Hint::set(Hint::ERROR, $error);
                 }
             }
             //No success saving the group, show the form again with the errors
             $this->_tpl->hints = Hint::render(null, true, 's4k/hint');
             $this->action_edit($group);
         } else {
             //No post request, redirect back to the edit group page
             $this->redirect(Route::url('S4K.groups.edit', array('id' => $id), true));
         }
     } catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e) {
         //set an error message an redirect to the management page
         Hint::set(Hint::ERROR, 'No corresponding group found');
         $this->redirect(Route::url('S4K.groups', null, true));
     }
 }
Beispiel #3
0
 public function action_edit_complete()
 {
     $id = $this->request->param('id');
     try {
         if ($this->request->post() != null) {
             $user = Sentry::getUserProvider()->findById($id);
             try {
                 $post = $this->request->post();
                 $values = array('email', 'password', 'first_name', 'last_name', 'permissions');
                 //if no password was provided remove the values (to ensure no empty password in the table)
                 if (empty($post['password'])) {
                     unset($post['password']);
                     unset($values[1]);
                 }
                 //set all posted permissions to 1
                 if (array_key_exists('permissions', $post) && count($post['permissions'] > 0)) {
                     $list = array();
                     foreach ($post['permissions'] as $key) {
                         $list[$key] = 1;
                     }
                     $post['permissions'] = $list;
                 }
                 //save the user
                 $user->values($post, $values)->save();
                 //if groups were defined set them (and delete the old ones)
                 if (count($post['groups']) > 0) {
                     $user->set_groups($post['groups']);
                 }
                 //everything went fine, set success msg and redirect to the management page
                 Hint::set(Hint::SUCCESS, 'You\'ve successfully updated user "#' . $user->id);
                 $this->redirect(Route::url('S4K.users.manage', null, true));
             } catch (ORM_Validation_Exception $e) {
                 //set errors as hints
                 foreach ($e->errors('model') as $error) {
                     Hint::set(Hint::ERROR, $error);
                 }
             }
             //No success saving the user, show the form again with the errors
             $this->_tpl->hints = Hint::render(null, true, 's4k/hint');
             $this->action_edit($user);
         } else {
             $this->redirect(Route::url('S4K.users.manage.edit', array('id' => $id), true));
         }
     } catch (\Cartalyst\Sentry\Users\UserNotFoundException $e) {
         Hint::set(Hint::ERROR, 'No corresponding user found');
         $this->redirect(Route::url('S4K.users.manage', null, true));
     }
 }
Beispiel #4
0
 public function before()
 {
     $this->_tpl = View::factory('s4k/layout');
     $this->_tpl->hints = Hint::render(null, true, 's4k/hint');
 }