2016-03-25 01:18:05 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Image;
|
|
|
|
use Input;
|
|
|
|
use Redirect;
|
|
|
|
use App\Models\Location;
|
|
|
|
use View;
|
|
|
|
use Auth;
|
|
|
|
use App\Helpers\Helper;
|
2016-10-29 05:50:55 -07:00
|
|
|
use App\Models\Setting;
|
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]
|
|
|
|
* @return View
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function getIndex()
|
|
|
|
{
|
|
|
|
// Get the user information
|
|
|
|
$user = Auth::user();
|
|
|
|
$location_list = Helper::locationsList();
|
|
|
|
return View::make('account/profile', compact('user'))->with('location_list', $location_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
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]
|
|
|
|
* @return Redirect
|
|
|
|
*/
|
2016-03-25 01:18:05 -07:00
|
|
|
public function postIndex()
|
|
|
|
{
|
|
|
|
|
|
|
|
// Grab the user
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
// Update the user information
|
2016-03-25 15:24:12 -07:00
|
|
|
$user->first_name = e(Input::get('first_name'));
|
|
|
|
$user->last_name = e(Input::get('last_name'));
|
|
|
|
$user->website = e(Input::get('website'));
|
|
|
|
$user->location_id = e(Input::get('location_id'));
|
|
|
|
$user->gravatar = e(Input::get('gravatar'));
|
|
|
|
$user->locale = e(Input::get('locale'));
|
2016-03-25 01:18:05 -07:00
|
|
|
|
2016-10-29 05:50:55 -07:00
|
|
|
if ((Setting::getSettings()->two_factor_enabled=='1') && (!config('app.lock_passwords'))) {
|
|
|
|
$user->two_factor_optin = e(Input::get('two_factor_optin', '0'));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|