Files
snipe-it/app/controllers/account/ProfileController.php
T
2013-11-29 16:08:18 -05:00

73 lines
1.6 KiB
PHP
Executable File

<?php namespace Controllers\Account;
use AuthorizedController;
use Input;
use Redirect;
use Sentry;
use Validator;
use Location;
use View;
class ProfileController extends AuthorizedController {
/**
* User profile page.
*
* @return View
*/
public function getIndex()
{
// Get the user information
$user = Sentry::getUser();
// Show the page
$location_list = array('' => 'Select One') + Location::lists('name', 'id');
// Show the page
return View::make('frontend/account/profile', compact('user'))->with('location_list',$location_list);
}
/**
* User profile form processing page.
*
* @return Redirect
*/
public function postIndex()
{
// Declare the rules for the form validation
$rules = array(
'first_name' => 'required|min:3',
'last_name' => 'required|min:3',
'location_id' => 'required',
'website' => 'url',
'gravatar' => 'email',
);
// Create a new validator instance from our validation rules
$validator = Validator::make(Input::all(), $rules);
// If validation fails, we'll exit the operation now.
if ($validator->fails())
{
// Ooops.. something went wrong
return Redirect::back()->withInput()->withErrors($validator);
}
// Grab the user
$user = Sentry::getUser();
// Update the user information
$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->save();
// Redirect to the settings page
return Redirect::route('profile')->with('success', 'Account successfully updated');
}
}