/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $user = Sentinel::findById($id); $activation = Activation::exists($user); $posts = Post::with(['thread', 'thread.category'])->where('user_id', $user->id)->orderBy('created_at', 'desc')->get(); return view('admin.users.show', compact('user', 'activation', 'posts')); }
/** * User update form processing page. * * @param User $user * @param UserRequest $request * @return Redirect */ public function update(User $user, UserRequest $request) { try { $user->first_name = $request->get('first_name'); $user->last_name = $request->get('last_name'); $user->email = $request->get('email'); $user->dob = $request->get('dob'); $user->bio = $request->get('bio'); $user->gender = $request->get('gender'); $user->country = $request->get('country'); $user->state = $request->get('state'); $user->city = $request->get('city'); $user->address = $request->get('address'); $user->postal = $request->get('postal'); if ($password = $request->has('password')) { $user->password = Hash::make($password); } // is new image uploaded? if ($file = $request->file('pic')) { $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/users/'; $destinationPath = public_path() . $folderName; $safeName = str_random(10) . '.' . $extension; $file->move($destinationPath, $safeName); //delete old pic if exists if (File::exists(public_path() . $folderName . $user->pic)) { File::delete(public_path() . $folderName . $user->pic); } //save new file path into db $user->pic = $safeName; } //save record $user->save(); // Get the current user groups $userRoles = $user->roles()->lists('id')->all(); // Get the selected groups $selectedRoles = $request->get('groups', array()); // Groups comparison between the groups the user currently // have and the groups the user wish to have. $rolesToAdd = array_diff($selectedRoles, $userRoles); $rolesToRemove = array_diff($userRoles, $selectedRoles); // Assign the user to groups foreach ($rolesToAdd as $roleId) { $role = Sentinel::findRoleById($roleId); $role->users()->attach($user); } // Remove the user from groups foreach ($rolesToRemove as $roleId) { $role = Sentinel::findRoleById($roleId); $role->users()->detach($user); } // Activate / De-activate user $status = $activation = Activation::completed($user); if ($request->get('activate') != $status) { if ($request->get('activate')) { $activation = Activation::exists($user); if ($activation) { Activation::complete($user, $activation->code); } } else { //remove existing activation record Activation::remove($user); //add new record Activation::create($user); //send activation mail $data = array('user' => $user, 'activationUrl' => URL::route('activate', $user->id, Activation::exists($user)->code)); // Send the activation code through email Mail::send('emails.register-activate', $data, function ($m) use($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); $m->subject('Welcome ' . $user->first_name); }); } } // Was the user updated? if ($user->save()) { // Prepare the success message $success = Lang::get('users/message.success.update'); // Redirect to the user page return Redirect::route('admin.users.edit', $user)->with('success', $success); } // Prepare the error message $error = Lang::get('users/message.error.update'); } catch (UserNotFoundException $e) { // Prepare the error message $error = Lang::get('users/message.user_not_found', compact('user')); // Redirect to the user management page return Redirect::route('users')->with('error', $error); } // Redirect to the user page return Redirect::route('admin.users.edit', $user)->withInput()->with('error', $error); }
/** * get account activate metod * * @param integer $id * @param string $code * @return Redirector */ public function accountActivate($id, $code) { try { $user = Sentinel::findById($id); if (is_null($user) || !Activation::exists($user)) { throw new ActivateException($id, $code, 'not_found'); } if (!Activation::complete($user, $code)) { throw new ActivateException($id, $code, 'fail'); } $user->is_active = true; $user->save(); Sentinel::login($user); Flash::success(trans('laravel-user-module::auth.activation.success')); // event fire event(new ActivateSuccess($user)); return redirect(lmbRoute(config('laravel-user-module.url.redirect_route'))); } catch (ActivateException $e) { Flash::error(trans('laravel-user-module::auth.activation.' . $e->getType())); // event fire event(new ActivateFail($e->getId(), $e->getActivationCode(), $e->getType())); return redirect(lmbRoute('getLogin')); } }
/** * User update form processing page. * * @param int $id * @return Redirect */ public function postEdit($id = null) { try { // Get the user information $user = Sentinel::findById($id); } catch (UserNotFoundException $e) { // Prepare the error message $error = Lang::get('users/message.user_not_found', compact('id')); // Redirect to the user management page return Redirect::route('users')->with('error', $error); } // $this->validationRules['email'] = "required|email|unique:users,email,{$user->email},email"; // Do we want to update the user password? if (!($password = Input::get('password'))) { unset($this->validationRules['password']); unset($this->validationRules['password_confirm']); } // Create a new validator instance from our validation rules $validator = Validator::make(Input::all(), $this->validationRules); // If validation fails, we'll exit the operation now. if ($validator->fails()) { // Ooops.. something went wrong return Redirect::back()->withInput()->withErrors($validator); } try { // Update the user $user->first_name = Input::get('first_name'); $user->last_name = Input::get('last_name'); $user->email = Input::get('email'); $user->dob = Input::get('dob'); $user->bio = Input::get('bio'); $user->gender = Input::get('gender'); $user->country = Input::get('country'); $user->state = Input::get('state'); $user->city = Input::get('city'); $user->address = Input::get('address'); $user->postal = Input::get('postal'); // Do we want to update the user password? if ($password) { $user->password = Hash::make($password); } // is new image uploaded? if ($file = Input::file('pic')) { $fileName = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/users/'; $destinationPath = public_path() . $folderName; $safeName = str_random(10) . '.' . $extension; $file->move($destinationPath, $safeName); //delete old pic if exists if (File::exists(public_path() . $folderName . $user->pic)) { File::delete(public_path() . $folderName . $user->pic); } //save new file path into db $user->pic = $safeName; } // Get the current user groups $userRoles = $user->roles()->lists('id')->all(); // Get the selected groups $selectedRoles = Input::get('groups', array()); // Groups comparison between the groups the user currently // have and the groups the user wish to have. $rolesToAdd = array_diff($selectedRoles, $userRoles); $rolesToRemove = array_diff($userRoles, $selectedRoles); // Assign the user to groups foreach ($rolesToAdd as $roleId) { $role = Sentinel::findRoleById($roleId); $role->users()->attach($user); } // Remove the user from groups foreach ($rolesToRemove as $roleId) { $role = Sentinel::findRoleById($roleId); $role->users()->detach($user); } // Activate / De-activate user $status = $activation = Activation::completed($user); if (Input::get('activate') != $status) { if (Input::get('activate')) { $activation = Activation::exists($user); if ($activation) { Activation::complete($user, $activation->code); } } else { //remove existing activation record Activation::remove($user); //add new record Activation::create($user); //send activation mail $data = array('user' => $user, 'activationUrl' => URL::route('activate', $user->id, Activation::exists($user)->code)); // Send the activation code through email Mail::send('emails.register-activate', $data, function ($m) use($user) { $m->to($user->email, $user->first_name . ' ' . $user->last_name); $m->subject('Welcome ' . $user->first_name); }); } } // Was the user updated? if ($user->save()) { // Prepare the success message $success = Lang::get('users/message.success.update'); // Redirect to the user page return Redirect::route('users.update', $id)->with('success', $success); } // Prepare the error message $error = Lang::get('users/message.error.update'); } catch (LoginRequiredException $e) { $error = Lang::get('users/message.user_login_required'); } // Redirect to the user page return Redirect::route('users.update', $id)->withInput()->with('error', $error); }
public function getActivation($id = null, $code = null) { if (is_null($id) || is_null($code)) { throw new NotFoundHttpException(); } $user = Sentinel::findById($id); if (!empty($user) || $user != null) { if (Activation::exists($user) != false) { if (Activation::completed($user) != false) { list($type, $msg) = ['error', 'auth.validatecompleted']; } else { Activation::complete($user, $code); list($type, $msg) = ['mensaje', 'auth.validate_email']; } } else { list($type, $msg) = ['error', 'auth.validatenotfound']; } } else { list($type, $msg) = ['error', 'auth.usernotfound']; } return redirect('/')->with($type, trans($msg)); }
/** * 激活已注册用户 - 业务逻辑 * * @param $user_id * @param string $route_success * @param string $route_failed * @return \Illuminate\Http\RedirectResponse */ public function active_logic($user_id, $route_success = 'account_list_get', $route_failed = 'account_list_get') { $user_info = Sentinel::findById($user_id); if (!$user_info) { // dump('用户不存在'); return redirect()->route($route_failed); } //TODO::检查是否已完成激活 $activation_completed_return = Activation::completed($user_info); if ($activation_completed_return) { // dump('账号已激活'); return redirect()->route($route_failed); } else { //TODO::检查是否已生成激活码 $activation_code = ''; $activation_exists_return = Activation::exists($user_info); if ($activation_exists_return) { // dump('已生成激活码'); $activation_code = $activation_exists_return['code']; } else { // dump('第一次生成激活码'); //TODO::生成激活码,返回生成的activations表记录 $activation_create_return = Activation::create($user_info); $activation_code = $activation_create_return['code']; } // dump($activation_code); //TODO::使用激活码,激活用户 $activation_complete_return = Activation::complete($user_info, $activation_code); if ($activation_complete_return) { // dump('完成激活'); return redirect()->route($route_success); } else { // dump('激活失败'); return redirect()->route($route_failed); } } }