public function update(Requests\SaveUserRequest $request, $id)
 {
     $user = User::findOrFail($id);
     // Account and contact information
     $old_password = $user->password;
     $user->fill($request->input());
     $new_password = $request->input('password');
     if (!empty($new_password)) {
         $user->password = bcrypt($new_password);
     } else {
         $user->password = $old_password;
     }
     // Avatar picture
     $file = Input::file('avatar');
     if ($file) {
         $path = 'uploads/avatars';
         $extension = $file->getClientOriginalExtension();
         $fileName = $user->username . '.' . $extension;
         $file->move($path, $fileName);
         Session::flash('success', 'Upload successfully');
         $user->avatar = $fileName;
     }
     // Save
     $user->save();
     // Redirect
     return redirect()->action('UserController@show', [$user->id]);
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(SaveUserRequest $request)
 {
     $data = ['name' => $request->get('name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'user' => $request->get('user'), 'password' => $request->get('password'), 'type' => $request->get('type'), 'active' => $request->has('active') ? 1 : 0, 'address' => $request->get('address')];
     $user = User::create($data);
     $message = $user ? 'User was added successfully!' : 'Could not add the user!';
     return redirect()->route('admin.user.index')->with('message', $message);
 }
Ejemplo n.º 3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(SaveUserRequest $request)
 {
     $data = ['name' => $request->get('name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'user' => $request->get('user'), 'password' => $request->get('password'), 'type' => $request->get('type'), 'active' => $request->has('active') ? 1 : 0, 'address' => $request->get('address')];
     $user = User::create($data);
     $message = $user ? 'Usuario agregado correctamente!' : 'El usuario NO pudo agregarse!';
     return redirect()->route('admin.user.index')->with('message', $message);
 }
Ejemplo n.º 4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(SaveUserRequest $request, User $user)
 {
     $user->update($request->all());
     return redirect('users');
 }
Ejemplo n.º 5
0
 /**
  * Validate and store the new user data, or return an error.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v1.0]
  * @return Redirect
  */
 public function postCreate(SaveUserRequest $request)
 {
     $user = new User();
     //Username, email, and password need to be handled specially because the need to respect config values on an edit.
     $user->email = $data['email'] = e($request->input('email'));
     $user->username = $data['username'] = e($request->input('username'));
     if ($request->has('password')) {
         $user->password = bcrypt($request->input('password'));
         $data['password'] = $request->input('password');
     }
     // Update the user
     $user->first_name = e($request->input('first_name'));
     $user->last_name = e($request->input('last_name'));
     $user->locale = e($request->input('locale'));
     $user->employee_num = e($request->input('employee_num'));
     $user->activated = e($request->input('activated', $user->activated));
     $user->jobtitle = e($request->input('jobtitle'));
     $user->phone = e($request->input('phone'));
     $user->location_id = e($request->input('location_id'));
     $user->company_id = e(Company::getIdForUser($request->input('company_id')));
     $user->manager_id = e($request->input('manager_id'));
     $user->notes = e($request->input('notes'));
     $user->permissions = json_encode($request->input('permission'));
     if ($user->manager_id == "") {
         $user->manager_id = null;
     }
     if ($user->location_id == "") {
         $user->location_id = null;
     }
     if ($user->company_id == "") {
         $user->company_id = null;
     }
     if ($user->save()) {
         if ($request->has('groups')) {
             $user->groups()->sync($request->input('groups'));
         } else {
             $user->groups()->sync(array());
         }
         if ($request->input('email_user') == 1 && $request->has('email')) {
             // Send the credentials through email
             $data = array();
             $data['email'] = e($request->input('email'));
             $data['username'] = e($request->input('username'));
             $data['first_name'] = e($request->input('first_name'));
             $data['password'] = e($request->input('password'));
             Mail::send('emails.send-login', $data, function ($m) use($user) {
                 $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                 $m->subject('Welcome ' . $user->first_name);
             });
         }
         return redirect::route('users')->with('success', trans('admin/users/message.success.create'));
     }
     return redirect()->back()->withInput()->withErrors($user->getErrors());
 }