/** * @param string $userAgent * @return integer */ public static function getId($userAgent) { $hash = md5($userAgent); $search = UserAgent::model()->find("hash = ?", $hash); if ($search) { return $search->id; } $ua = new UserAgent(); $ua->userAgent = $userAgent; $ua->hash = md5($userAgent); $ua->save(); return $ua->id; }
/** * Change user profile settings. Three actions can be performed: * - Change User information (name and email) * - Change password * - Generate API key -- used for external API data calls. */ public function postSettings(UserAgent $user) { $action = Input::get('action'); if ($action == 'userinfo') { // Change user details $user['firstname'] = Input::get('firstname'); $user['lastname'] = Input::get('lastname'); $user['email'] = Input::get('email'); $user->save(); Session::flash('flashSuccess', 'Profile information succesfully changed'); } elseif ($action == 'password') { // Change user password $currPass = Input::get('oldpassword'); if ($user->checkPassword($currPass)) { $newPass1 = Input::get('newpassword1'); $newPass2 = Input::get('newpassword2'); if ($newPass1 == $newPass2) { $user->password = $newPass1; $user->save(); Session::flash('flashSuccess', 'Password succesfully changed'); } else { return Redirect::back()->with('flashError', 'New passwords do not match'); } } else { return Redirect::back()->with('flashError', 'Incorrect password'); } } elseif ($action == 'apikey') { // Generate new API key $user['api_key'] = hash('sha256', Str::random(10), false); $user->save(); Session::flash('flashSuccess', 'New API key generated'); } return Redirect::back(); }