2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Image;
|
|
|
|
use Input;
|
|
|
|
use Redirect;
|
|
|
|
use View;
|
|
|
|
use Auth;
|
|
|
|
use App\Helpers\Helper;
|
2016-10-29 05:50:55 -07:00
|
|
|
use App\Models\Setting;
|
2016-10-31 16:52:25 -07:00
|
|
|
use Gate;
|
2017-08-22 12:09:04 -07:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-04-07 13:21:09 -07:00
|
|
|
/**
|
|
|
|
* This controller handles all actions related to User Profiles for
|
|
|
|
* the Snipe-IT Asset Management application.
|
|
|
|
*
|
|
|
|
* @version v1.0
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
class ProfileController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Returns a view with the user's profile form for editing
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getIndex()
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
$location_list = Helper::locationsList();
|
2017-06-09 16:44:03 -07:00
|
|
|
return view('account/profile', compact('user'))->with('location_list', $location_list);
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-07 13:39:35 -07:00
|
|
|
* Validates and stores the user's update data.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v1.0]
|
2016-12-19 22:00:50 -08:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function postIndex()
|
|
|
|
{
|
|
|
|
|
|
|
|
$user = Auth::user();
|
2016-12-19 22:00:50 -08:00
|
|
|
$user->first_name = Input::get('first_name');
|
|
|
|
$user->last_name = Input::get('last_name');
|
|
|
|
$user->website = Input::get('website');
|
|
|
|
$user->location_id = Input::get('location_id');
|
|
|
|
$user->gravatar = Input::get('gravatar');
|
|
|
|
$user->locale = Input::get('locale');
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-10-31 16:52:25 -07:00
|
|
|
if ((Gate::allows('self.two_factor')) && ((Setting::getSettings()->two_factor_enabled=='1') && (!config('app.lock_passwords')))) {
|
2016-12-19 22:00:50 -08:00
|
|
|
$user->two_factor_optin = Input::get('two_factor_optin', '0');
|
2016-10-29 05:50:55 -07:00
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
if (Input::file('avatar')) {
|
|
|
|
$image = Input::file('avatar');
|
2016-08-30 12:34:23 -07:00
|
|
|
$file_name = str_slug($user->first_name."-".$user->last_name).".".$image->getClientOriginalExtension();
|
2016-03-25 01:18:05 -07:00
|
|
|
$path = public_path('uploads/avatars/'.$file_name);
|
|
|
|
Image::make($image->getRealPath())->resize(84, 84)->save($path);
|
|
|
|
$user->avatar = $file_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::get('avatar_delete') == 1 && Input::file('avatar') == "") {
|
|
|
|
$user->avatar = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($user->save()) {
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->route('profile')->with('success', 'Account successfully updated');
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2016-04-28 21:06:41 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($user->getErrors());
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|
2017-01-24 17:37:07 -08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a page with the API token generation interface.
|
|
|
|
*
|
|
|
|
* We created a controller method for this because closures aren't allowed
|
|
|
|
* in the routes file if you want to be able to cache the routes.
|
|
|
|
*
|
|
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
|
|
* @since [v4.0]
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function api() {
|
|
|
|
return view('account/api');
|
|
|
|
}
|
2017-08-22 12:09:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User change email page.
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function password()
|
|
|
|
{
|
|
|
|
$user = Auth::user();
|
|
|
|
return view('account/change-password', compact('user'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Users change password form processing page.
|
|
|
|
*
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
|
|
|
public function passwordSave(Request $request)
|
|
|
|
{
|
2017-08-22 12:22:32 -07:00
|
|
|
|
2017-08-22 12:09:04 -07:00
|
|
|
if (config('app.lock_passwords')) {
|
|
|
|
return redirect()->route('account.password.index')->with('error', Lang::get('admin/users/table.lock_passwords'));
|
2017-08-22 12:22:32 -07:00
|
|
|
}
|
2017-08-22 12:09:04 -07:00
|
|
|
|
2017-08-22 12:22:32 -07:00
|
|
|
$user = Auth::user();
|
|
|
|
if ($user->ldap_import=='1') {
|
|
|
|
return redirect()->route('account.password.index')->with('error', Lang::get('admin/users/message.error.password_ldap'));
|
|
|
|
}
|
2017-08-22 12:09:04 -07:00
|
|
|
|
2017-08-22 12:22:32 -07:00
|
|
|
$rules = array(
|
|
|
|
'current_password' => 'required',
|
|
|
|
'password' => 'required|min:6',
|
|
|
|
'password_confirm' => 'required|same:password',
|
|
|
|
);
|
2017-08-22 12:09:04 -07:00
|
|
|
|
2017-08-22 12:22:32 -07:00
|
|
|
$validator = \Validator::make($request->all(), $rules);
|
|
|
|
$validator->after(function($validator) use ($request, $user) {
|
2017-08-22 12:09:04 -07:00
|
|
|
|
2017-08-22 12:22:32 -07:00
|
|
|
if (!Hash::check($request->input('current_password'), $user->password)) {
|
|
|
|
$validator->errors()->add('current_password', trans('validation.hashed_pass'));
|
2017-08-22 12:09:04 -07:00
|
|
|
}
|
2017-08-22 12:22:32 -07:00
|
|
|
|
|
|
|
});
|
2017-08-22 12:09:04 -07:00
|
|
|
|
2017-08-22 12:22:32 -07:00
|
|
|
if (!$validator->fails()) {
|
|
|
|
$user->password = Hash::make($request->input('password'));
|
|
|
|
$user->save();
|
|
|
|
return redirect()->route('account.password.index')->with('success', 'Password updated!');
|
2017-08-22 12:09:04 -07:00
|
|
|
|
|
|
|
}
|
2017-08-22 12:22:32 -07:00
|
|
|
return redirect()->back()->withInput()->withErrors($validator);
|
2017-08-22 12:09:04 -07:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-22 12:22:32 -07:00
|
|
|
|
2016-03-25 01:18:05 -07:00
|
|
|
}
|