/** * process the login submit. * * @return Response */ public function login() { $potential_user = \Pinom\Models\User::where('email', 'LIKE', \Input::has('email') ? \Input::get('email') : '')->first(); if (!is_null($potential_user) && trim($potential_user->password) == '') { //echo "isnull password!"; $user = \Sentinel::findById($potential_user->id); $password = ['password' => $potential_user->id . '.' . $potential_user->email]; $user = \Sentinel::update($user, $password); $activation = \Activation::create($user); $activation = \Activation::complete($user, $activation->code); } $credentials = ['email' => \Input::has('email') ? \Input::get('email') : '', 'password' => \Input::has('passw') ? \Input::get('passw') : '']; //echo '<pre>'; //return redirect('/'); $user = \Sentinel::authenticate($credentials); //print_R($user); if ($user = \Sentinel::check()) { return redirect('/login'); } else { return redirect('/login'); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // dd($request); //get user u ant to update $user = \Sentinel::findById($id); //get the persons details $staff = Staff::find($request->user); $data = $request->except('_token'); $rules = ['password' => 'min:4|required']; $validator = \Validator::make($data, $rules); if ($validator->passes()) { //array to hold final permission values $array_of_permissions = Helper::prepPermissions($request->exempt_permission, 'false'); $credentials = ['email' => $staff->email, 'password' => $request->password, 'permissions' => $array_of_permissions, 'staff_id' => $staff->id, 'first_name' => $staff->fname, 'last_name' => $staff->lname]; //update user $user = \Sentinel::update($user, $credentials); //get the id(s) of the current roles of this user in an array $current_roles = array(); foreach ($user->roles as $value) { $current_roles[] = $value->id; } //compute role(s) to add $add_roles = array_diff($request->assign_roles, $current_roles); //compute role(s) to delete $delete_roles = array_diff($current_roles, $request->assign_roles); //update user role(s) $user = \Sentinel::findById($user->id); //add ne role(s) foreach ($add_roles as $role_id) { $role = \Sentinel::findRoleById($role_id); $role->users()->attach($user); } //delete role(s), if any foreach ($delete_roles as $role_id) { \DB::table('role_users')->where('role_id', $role_id)->where('user_id', $user->id)->delete(); } return \Redirect::to('settings/users/create'); } else { return \Redirect::back()->withInput()->withErrors($validator); } }
<?php return array('view' => array('list' => function (array $row) { }, 'form' => function (array $row) { // empty if create form return view('jarboe.c.users::patterns.user_password'); }), 'handle' => array('insert' => function ($idRow, $patternValue, $values) { $password = trim($patternValue); if (!$password) { // FIXME: translations throw new \Yaro\Jarboe\Exceptions\JarboeValidationException('Пароль обязательное поле'); } $user = \Sentinel::findById($idRow); \Sentinel::update($user, compact('password')); }, 'update' => function ($idRow, $patternValue, $values) { $password = trim($patternValue); if (!$password) { return; } $user = \Sentinel::findById($idRow); \Sentinel::update($user, compact('password')); }, 'delete' => function ($idRow) { }));