Esempio n. 1
0
 /**
  * Save the first admin user from Setup.
  *
  * @author [A. Gianotto] [<*****@*****.**>]
  * @since [v3.0]
  * @return Redirect
  */
 public function postSaveFirstAdmin(SetupUserRequest $request)
 {
     $user = new User();
     $user->first_name = $data['first_name'] = e(Input::get('first_name'));
     $user->last_name = e(Input::get('last_name'));
     $user->email = $data['email'] = e(Input::get('email'));
     $user->activated = 1;
     $permissions = array('superuser' => 1);
     $user->permissions = json_encode($permissions);
     $user->username = $data['username'] = e(Input::get('username'));
     $user->password = bcrypt(Input::get('password'));
     $data['password'] = Input::get('password');
     $settings = new Setting();
     $settings->site_name = e(Input::get('site_name'));
     $settings->alert_email = e(Input::get('email'));
     $settings->alerts_enabled = 1;
     $settings->brand = 1;
     $settings->locale = 'en';
     $settings->default_currency = 'USD';
     $settings->user_id = 1;
     $settings->email_domain = e(Input::get('email_domain'));
     $settings->email_format = e(Input::get('email_format'));
     if (!$user->isValid() || !$settings->isValid()) {
         return redirect()->back()->withInput()->withErrors($user->getErrors())->withErrors($settings->getErrors());
     } else {
         $user->save();
         $settings->save();
         if (Input::get('email_creds') == '1') {
             Mail::send(['text' => 'emails.firstadmin'], $data, function ($m) use($data) {
                 $m->to($data['email'], $data['first_name']);
                 $m->subject('Your Snipe-IT credentials');
             });
         }
         return redirect()->route('setup.done');
     }
 }