/**
  * Ask for new superuser password with confirmation
  *
  * @param  integer $attemps Max number of attemps
  *
  * @return bool
  */
 protected function askNewPassword($attemps = 3)
 {
     if ($attemps-- <= 0) {
         throw new Exception('Max number of attemps exceeded');
     }
     $this->superuser->password = $this->secret('Enter NEW superuser password: '******'Enter NEW superuser password again: ');
     if ($this->superuser->validate()) {
         return true;
     }
     $this->showValidationErrors();
     return $this->askNewPassword($attemps);
 }
Example #2
0
 /**
  * Log in check.
  * Password should be encrypted and validation should be done in the model.
  * Should use select to get the columns you are interested in.
  * 
  * @param Request
  */
 public function user(Request $request)
 {
     $name = $request->input('name');
     $password = $request->input('password');
     $user = User::validate($name, $password);
     if (!$user) {
         return redirect('/')->withErrors('Failed to validate user name or password');
     }
     $group = Group::getUserGroup($user);
     return redirect($group);
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // TODO: add check if current user is admin before he can add another admin
     $a = new User();
     if (!$a->validate(Input::all())) {
         return redirect('user/create')->withErrors($a->errors())->withInput();
     }
     $a->fill(Input::all());
     $a->save();
     $a->roles()->attach(Input::get('role'));
     Flash::success('New user is created');
     return Redirect::to('user');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Request::all();
     $validation = User::validate($input);
     if ($validation->fails()) {
         $message = $validation->messages()->first();
         return Response()->json(ResponseManager::getError('', 10, $message));
     }
     $input['password'] = Hash::make($input['password']);
     $user = User::create($input);
     if ($user) {
         $message = 'Added Successfully.';
         return Response()->json(ResponseManager::getResult($user, 10, $message));
     } else {
         $message = 'Something went wrong. Please try again.';
         return Response()->json(ResponseManager::getError('', 10, $message));
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postIndex(Request $request)
 {
     $usuario = new User();
     $inputs = $request->all();
     $usuario->fill($inputs);
     if ($usuario->validate()) {
         if ($usuario->save()) {
             $usersGroup = Sentinel::findRoleById(2);
             $user = Sentinel::findUserById($usuario->id);
             $usersGroup->users()->attach($user);
             $this->generarActivationReminder($user, 'activation');
             return redirect('login')->with('mensaje', 'Se registró el usuario correctamente');
         } else {
             return back()->withInput()->withErrors($usuario->getErrors());
         }
     } else {
         return back()->withInput()->withErrors($usuario->getErrors());
     }
 }
 /**
  * Function setting account of user
  * @method POST
  * @author Tran Van Moi
  * @since  2015/05/20
  * @return response
  */
 public function postSetting()
 {
     $data = Input::all();
     $validator = User::validate($data, 'edit');
     if ($validator->fails()) {
         return redirect('user/setting')->withInput()->withErrors($validator);
     } else {
         if (Hash::check($data['current_password'], Auth::user()->password)) {
             $user = Auth::user();
             $user->name = $data['name'];
             $user->address = $data['address'];
             $user->birthday = $data['birthday'];
             if (Input::file('image')) {
                 $destination_path = './public/images/avatar/';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $file_name = str_random(8) . '.' . $extension;
                 // renameing image
                 if (Input::file('image')->move($destination_path, $file_name)) {
                     if ($user->image != "default.jpg" && File::exists($destination_path . $user->image)) {
                         File::delete($destination_path . $user->image);
                     }
                     $user->image = $file_name;
                 }
             }
             if ($data['password'] != "" && $data['password'] == $data['password_confirmation']) {
                 $user->password = Hash::make($data['password']);
             }
             $user->save();
             $url_image = LibraryPublic::get_url_image($user->image);
             Session::put('url_image_auth', $url_image);
             return redirect('user/setting')->withInput()->with('setting_status', ['status' => 'success', 'message' => 'Setting account is success!']);
         } else {
             return redirect('user/setting')->withInput()->with('setting_status', ['status' => 'danger', 'message' => 'Password is not correct']);
         }
     }
 }
 /**
  * Admin edit user
  * @author  Tran Van Moi
  * @since  2015/06/01
  * @param  int $id
  * @return Response
  */
 public function postEdit($id = null)
 {
     $id = trim($id);
     $user = User::find($id);
     if ($user) {
         $data = Input::all();
         $data['id'] = $id;
         $validator = User::validate($data, 'admin-edit');
         if ($validator->fails()) {
             return Redirect::to('admin/user/edit/' . $id)->withInput()->withErrors($validator);
         } else {
             $user->name = $data['name'];
             $user->email = $data['email'];
             $user->birthday = $data['birthday'];
             $user->address = $data['address'];
             if (Input::file('image')) {
                 $destination_path = './public/images/avatar/';
                 // upload path
                 $extension = Input::file('image')->getClientOriginalExtension();
                 // getting image extension
                 $file_name = str_random(8) . '.' . $extension;
                 // renameing image
                 if (Input::file('image')->move($destination_path, $file_name)) {
                     if ($user->image != "default.jpg" && File::exists($destination_path . $user->image)) {
                         File::delete($destination_path . $user->image);
                     }
                     $user->image = $file_name;
                 }
             }
             if ($data['password'] != "") {
                 $user->password = Hash::make($data['password']);
             }
             $user->save();
             $url_image = LibraryPublic::get_url_image($user->image);
             Session::put('url_image_edit_user', $url_image);
             return redirect('admin/user/edit/' . $id)->withInput()->with('edit_status', ['status' => 'success', 'message' => 'Setting account is success!']);
         }
     } else {
         return redirect('admin/user/edit');
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id, EditUserRequest $request)
 {
     $vld = User::validate($request->all(), $id);
     if (!$vld->passes()) {
         // dd($vld->errors()->getMessages());
         return Redirect::back()->with('messageNo', $vld->errors()->getMessages()['username'][0]);
     }
     $user = User::find($id);
     $password = '';
     if ($request->password != '') {
         $password = bcrypt($request->password);
     } else {
         $password = $user->password;
     }
     $employee = Employee::find($request->get('employee_id'));
     $user->update(['employee_id' => $request->get('employee_id'), 'fullname' => $employee->lastname . " " . $employee->firstname, 'username' => $request->username, 'password' => $password]);
     $user->attachGroup($request['group_id']);
     return redirect()->route('users.index')->with('messageOk', 'Update user successfully');
 }