/** * Processes the form. * * @return \Illuminate\Http\RedirectResponse */ public function update() { $user = $this->currentUser; $rules = ['email' => "required|unique:users,email,{$user->email},email", 'password' => 'sometimes|required', 'password_confirm' => 'required_with:password|same:password']; $input = array_where(Input::get(), function ($key, $value) { if (str_contains($key, 'password') && empty($value)) { return false; } return true; }); $validator = Validator::make($input, $rules); $validator->passes(); $messages = $validator->errors(); if ($messages->isEmpty()) { try { Sentinel::getUserRepository()->update($user, $input); return Redirect::route('user.edit_profile')->withSuccess('Your profile was successfully updated.'); } catch (NotUniquePasswordException $e) { return Redirect::back()->withInput()->withErrors('This password was used before. You must choose a unique password.'); } } return Redirect::back()->withInput()->withErrors($messages); }
/** * Register user * * Registers a new user * * @Post("/") * @Versions({"v1"}) * @Transaction( * @Request({"name": "foo", "email": "*****@*****.**", "password": "******"}), * @Response(200, body={"id":"1"}), * @Response(422, body={"error": "existing", "field": "username|email", "message": "{field} already exists" }), * @Response(422, body={"error": "format", "field": "username|email|password", "message": "Bad {field} format: {reason}" }), * ) * @param \Dingo\Api\Contract\Http\Request $request * @return \Cartalyst\Sentinel\Users\UserInterface */ public function store(RequestContract $request) { $data = $request->all(); return $this->index(); $users = \Sentinel::getUserRepository(); try { if ($valid = $users->validForCreation($data)) { $user = $users->create($data); return $user; } } catch (InvalidArgumentException $e) { throw new BadRequestHttpException($e->getMessage()); } }
public function update_my_personal_profile_with_changes(FunctionalTester $I) { $I->am('Admin'); $I->wantTo('update my profile and change some informations'); $I->expectTo('see a success confirmation message and see that my data have changed'); /*************************************************************************************************************** * settings **************************************************************************************************************/ // we create the admin role $admin_role = $this->_createAdminRole(); // we attach it to the logged user $admin_role->users()->attach($this->_user); /*************************************************************************************************************** * run test **************************************************************************************************************/ $I->amOnPage('/'); $I->amOnRoute('users.profile'); $I->see(trans('users.page.title.profile'), 'h2'); $I->selectOption('gender', config('user.gender_key.male')); $I->fillField('last_name', 'OTHER'); $I->fillField('first_name', 'Other'); $I->fillField('birth_date', '01/01/1999'); $I->fillField('phone_number', '0101010101'); $I->fillField('email', '*****@*****.**'); $I->fillField('address', '1 impasse Commandant Cousteau'); $I->fillField('zip_code', 99456); $I->fillField('city', 'Toulon'); $I->fillField('country', 'Maroc'); $I->fillField('password', 'password'); $I->fillField('password_confirmation', 'password'); $I->click(trans('global.action.save')); $I->seeCurrentRouteIs('users.profile'); $I->see(trans('global.modal.alert.title.success'), 'h3'); $I->see(trans('users.message.account.success')); $this->_user->fresh(); $I->seeRecord('users', ['last_name' => 'OTHER', 'first_name' => 'Other', 'gender' => config('user.gender_key.male'), 'birth_date' => '1999-01-01', 'status_id' => $this->_user->status_id, 'board_id' => $this->_user->board_id, 'phone_number' => '+33 1 01 01 01 01', 'email' => '*****@*****.**', 'address' => '1 impasse Commandant Cousteau', 'zip_code' => 99456, 'city' => 'Toulon', 'country' => 'Maroc']); $I->seeRecord('role_users', ['user_id' => $this->_user->id, 'role_id' => Sentinel::findRoleBySlug('admin')->id]); $I->seeRecord('activations', ['user_id' => $this->_user->id, 'completed' => true]); $user = Sentinel::getUserRepository()->findByCredentials(['email' => '*****@*****.**']); $I->assertTrue(Hash::check('test', $user->password)); }
/** * Set the new password * @return $this */ public function SetForgotPassword() { try { $user = \Sentinel::getUserRepository()->findById(\Input::get('UserId')); if (\Reminder::complete($user, \Input::get('ResetCode'), \Input::get('password'))) { return redirect('auth/login')->withErrors(array('login' => 'Password reset successful. Please Login')); } else { return redirect('auth/forgotpassword')->withErrors(array('forgot_password' => 'Password reset failed')); } } catch (\Exception $e) { return redirect('auth/forgotpassword')->withErrors(array('forgot_password' => 'User not found in our database.')); } }
/** * Constructor. * * @return void */ public function __construct() { parent::__construct(); $this->users = Sentinel::getUserRepository(); $this->roles = Sentinel::getRoleRepository(); }