Ejemplo n.º 1
0
 public function postNew()
 {
     $validation = new Validators\SeatUserRegisterValidator();
     if ($validation->passes()) {
         // Let's register a user.
         $user = new \User();
         $user->email = Input::get('email');
         $user->username = Input::get('username');
         $user->password = Hash::make(Input::get('password'));
         $user->tsid = Input::get('tsid');
         $user->activation_code = str_random(24);
         $user->activated = 1;
         $user->save();
         // Prepare data to be sent along with the email. These
         // are accessed by their keys in the email template
         $data = array('activation_code' => $user->activation_code);
         // Send the email with the activation link
         Mail::send('emails.auth.register', $data, function ($message) {
             $message->to(Input::get('email'), 'New SeAT User')->subject('SeAT Account Confirmation');
         });
         // And were done. Redirect to the login again
         return Redirect::action('SessionController@getSignIn')->with('success', 'Successfully registered a new account. Please check your email for the activation link.');
     } else {
         return Redirect::back()->withInput()->withErrors($validation->errors);
     }
 }
Ejemplo n.º 2
0
 public function postNewUser()
 {
     // Grab the inputs and validate them
     $new_user = Input::only('email', 'username', 'password', 'first_name', 'last_name', 'is_admin');
     $validation = new Validators\SeatUserRegisterValidator();
     // Should the form validation pass, continue to attempt to add this user
     if ($validation->passes()) {
         // Because users are soft deleted, we need to check if if
         // it doesnt actually exist first.
         $user = \User::withTrashed()->where('email', Input::get('email'))->orWhere('username', Input::get('username'))->first();
         // If we found the user, restore it and set the
         // new values found in the post
         if ($user) {
             $user->restore();
         } else {
             $user = new \User();
         }
         // With the user object ready, work the update
         $user->email = Input::get('email');
         $user->username = Input::get('username');
         $user->password = Hash::make(Input::get('password'));
         $user->activated = 1;
         $user->save();
         // After user is saved and has a user_id
         // we can add it to the admin group if necessary
         if (Input::get('is_admin') == 'yes') {
             $adminGroup = \Auth::findGroupByName('Administrators');
             Auth::addUserToGroup($user, $adminGroup);
         }
         return Redirect::action('UserController@getAll')->with('success', 'User ' . Input::get('email') . ' has been added');
     } else {
         return Redirect::back()->withInput()->withErrors($validation->errors);
     }
 }