/** * Store a newly created resource in storage. * * @return Response */ public function postCreate() { $this->user->username = Input::get('username'); $this->user->email = Input::get('email'); $this->user->password = Input::get('password'); // The password confirmation will be removed from model // before saving. This field will be used in Ardent's // auto validation. $this->user->password_confirmation = Input::get('password_confirmation'); $this->user->confirmed = Input::get('confirm'); // Permissions are currently tied to roles. Can't do this yet. //$user->permissions = $user->roles()->preparePermissionsForSave(Input::get( 'permissions' )); // Save if valid. Password field will be hashed before save $this->user->engine_key = Hash::make(uniqid(mt_rand(), true)); $this->user->save(); try { // Register the user on the engine $return = xDockerEngine::register(array('username' => $this->user->username, 'password' => $this->user->engine_key)); Log::info("Return Status : " . $return); EngineLog::logIt(array('user_id' => $this->user->id, 'method' => 'admin:register', 'return' => $return)); } catch (Exception $e) { Log::error('Error while registering the user!' . $e->getMessage()); } if ($this->user->id) { // Save roles. Handles updating. $this->user->saveRoles(Input::get('roles')); // Redirect to the new user page return Redirect::to('admin/users/' . $this->user->id . '/edit')->with('success', Lang::get('admin/users/messages.create.success')); } else { // Get validation errors (see Ardent package) $error = $this->user->errors()->all(); return Redirect::to('admin/users/create')->withInput(Input::except('password'))->with('error', $error); } }
private static function checkSocialEmailAndLogin($email) { // Check if user with email exists, otherwise create one and finaly log them in // Used by socialLogin and amazonLogin $user = User::where('email', $email)->first(); if (empty($user)) { // Register $user = new User(); $user->email = $email; // Generate a username from the email for compatibility with Confide's schema $user->username = preg_replace('/[\\s\\W]+/', '_', $email); // Assign a random password for compatibility with Confide's Auth $randomPass = Hash::make(uniqid(mt_rand(), true)); $user->password = $randomPass; $user->password_confirmation = $randomPass; $user->confirmation_code = md5(uniqid(mt_rand(), true)); // Set as confirmed by default since we have social proof $user->confirmed = 1; $user->display_name = $user->username; $user->engine_key = Hash::make(uniqid(mt_rand(), true)); // var_dump('created', $user->save() , $user->errors()); if (!$user->save()) { throw new Exception($user->errors()); } // Register the user on the engine $return = xDockerEngine::register(array('username' => $user->username, 'password' => $user->engine_key)); Log::info("Return Status : " . $return); EngineLog::logIt(array('user_id' => $user->id, 'method' => 'register', 'return' => $return)); } // return Confide::logAttempt((array) $user); return Auth::loginUsingId($user->id); }