/**
  * To check if username is valid and existing
  * To check if username and password matched
  * Validation to proceed to Thread page
  **/
 public function index()
 {
     $username = Param::get('login_name');
     $password = Param::get('login_pword');
     $user = new User();
     $login_info = array('username' => $username, 'password' => $password);
     if (!array_filter($login_info)) {
         $status = "";
     } else {
         try {
             foreach ($login_info as $key => $value) {
                 if (!is_complete($value)) {
                     throw new ValidationException("Please fill up all fields");
                 }
             }
             $user_login = $user->authenticate($username, $password);
             $_SESSION['username'] = $user_login->username;
             redirect(url('thread/index'));
         } catch (ValidationException $e) {
             $status = notice($e->getMessage(), "error");
         } catch (RecordNotFoundException $e) {
             $status = notice($e->getMessage(), "error");
         }
     }
     $this->set(get_defined_vars());
 }
 /**
  * Disable BackendUser authentication redirect and cache the result
  */
 public function authenticate()
 {
     if ($this->frontendHelperUserAuthenticated === null) {
         $this->frontendHelperUserAuthenticated = \User::authenticate();
     }
     return $this->frontendHelperUserAuthenticated;
 }
 protected function set_current_user()
 {
     $user = null;
     $AnonymousUser = array('id' => 0, 'level' => 0, 'name' => "Anonymous", 'show_samples' => true, 'language' => '', 'secondary_languages' => '', 'pool_browse_mode' => 1, 'always_resize_images' => true, 'ip_addr' => $this->request()->remoteIp());
     if (!current_user() && $this->session()->user_id) {
         $user = User::where(['id' => $this->session()->user_id])->first();
     } else {
         if ($this->cookies()->login && $this->cookies()->pass_hash) {
             $user = User::authenticate_hash($this->cookies()->login, $this->cookies()->pass_hash);
         } elseif (isset($this->params()->login) && isset($this->params()->password_hash)) {
             $user = User::authenticate($this->params()->login, $this->params()->password_hash);
         } elseif (isset($this->params()->user['name']) && isset($this->params()->user['password'])) {
             $user = User::authenticate($this->params()->user['name'], $this->params()->user['password']);
         }
         $user && $user->updateAttribute('last_logged_in_at', date('Y-m-d H:i:s'));
     }
     if ($user) {
         if ($user->is_blocked() && $user->ban && $user->ban->expires_at < date('Y-m-d H:i:s')) {
             $user->updateAttribute('level', CONFIG()->starting_level);
             Ban::destroyAll("user_id = " . $user->id);
         }
         $this->session()->user_id = $user->id;
     } else {
         $user = new User();
         $user->assignAttributes($AnonymousUser, ['without_protection' => true]);
     }
     User::set_current_user($user);
     $this->current_user = $user;
     # For convenient access in activerecord models
     $user->ip_addr = $this->request()->remoteIp();
     Moebooru\Versioning\Versioning::init_history();
     if (!current_user()->is_anonymous()) {
         current_user()->log($this->request()->remoteIp());
     }
 }
Example #4
0
 function login($request)
 {
     $templateArr = array();
     $modelClass = 'User';
     $formData = array();
     if ($request->user->is_authenticated()) {
         HttpResponseRedirect(pjango_ini_get('LOGIN_REDIRECT_URL'));
     }
     if ($request->POST) {
         $form = new Pjango\Contrib\Auth\Forms\LoginForm($request->POST);
         try {
             if (!$form->is_valid()) {
                 throw new Exception(pjango_gettext('There are some errors, please correct them below.'));
             }
             $formData = $form->cleaned_data();
             $user = User::authenticate($formData['username'], $formData['password']);
             HttpResponseRedirect(pjango_ini_get('LOGIN_REDIRECT_URL'));
         } catch (Exception $e) {
             Messages::Error($e->getMessage());
         }
     }
     if (!$form) {
         $form = new Pjango\Contrib\Auth\Forms\LoginForm($formData);
     }
     $templateArr['addchange_form'] = $form->as_list();
     render_to_response('auth/login.html', $templateArr);
 }
 public function postLogin()
 {
     $email = Input::get('email');
     $password = Input::get('password');
     if (User::authenticate(['email' => $email, 'password' => $password], Input::has('rememberme'))) {
         return Redirect::intended('/admin');
     }
     return Redirect::to('/login')->withInput()->withErrors('Такой связки email и пароля нет.');
 }
Example #6
0
 public function create($username, $password)
 {
     $user = User::authenticate($username, $password);
     if ($user === false) {
         Redirect('session/create?error=yes');
     }
     $_SESSION['user'] = $user;
     Redirect('index.php');
 }
 public static function store()
 {
     $user = User::authenticate($_POST['username'], $_POST['password']);
     if ($user) {
         $_SESSION['user'] = $user->id;
         Redirect::to("/task", array('message' => "Welcome back."));
     }
     View::make('session/new.html', array('errors' => array("Wrong password or username.")));
 }
Example #8
0
function register($info = null)
{
    $session = mySession::getInstance();
    if ($session->isLoggedIn()) {
        $session->logout();
    }
    if ($info !== null) {
        //check email and username they have to be unique
        $check = User::getUserByCred($info->email, $info->username);
        if (!$check) {
            $temp_user = new User();
            $temp_user->username = $info->username;
            $temp_user->email = $info->email;
            $temp_user->password = sha1($info->password);
            $temp_user->first_name = $info->first;
            $temp_user->last_name = $info->last;
            $temp_user->gender = $info->gender;
            $temp_user->rights = 'normal';
            $temp_user->status = 'current';
            $temp_user->valid = 1;
            $temp_user->save();
            $found_user = User::authenticate($temp_user->username, $temp_user->password);
            if ($found_user) {
                // log them in
                $session->login($found_user);
                // grab the account status
                $profile_status = $found_user->status;
                if ($profile_status != 'current') {
                    // their account isn't set up so log them out send them to the login page.
                    $session->logout();
                    $session->message("Creating your user profile failed");
                    return false;
                } else {
                    // send verification email.
                    $to = $found_user->email;
                    $check = substr($found_user->password, -12);
                    $subject = "familyhistorydatabase.org verification email";
                    $message = "You are now registered at familyhistorydatabase.org.\n";
                    $message = $message . "\nTo verify your membership click on the link below.\nIf you weren't requesting membership, please ignore this email, and we send our appologies!";
                    $message = $message . "\n" . APIURL . "user/validate/?id=" . $found_user->id . "&validate={$check}";
                    $from = "*****@*****.**";
                    $headers = "From:" . $from;
                    mail($to, $subject, $message, $headers);
                    unset($found_user->password);
                    return $found_user;
                }
            }
        } else {
            // If User Not Found
            return false;
        }
    } else {
        // If User Not Found
        return false;
    }
    exit;
}
Example #9
0
 public static function login($parameters)
 {
     $id = User::authenticate($parameters);
     if ($id != null) {
         $content["success"] = "Login was succesful";
     } else {
         $content["error"] = "Login failed. Username/password combination was invalid.";
     }
     return $content;
 }
Example #10
0
 public static function login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if ($user) {
         $_SESSION['user'] = $user->id;
         Redirect::to(\Slim\Slim::getInstance()->urlFor('index'), array('message' => 'Olet kirjautunut sisään'));
     } else {
         Redirect::to(\Slim\Slim::getInstance()->urlFor('login'), array('message' => 'Kirjautuminen epäonnistui', 'error' => true));
     }
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Invalid username or password!', 'username' => $params['username']));
     } else {
         $_SESSION['user'] = $user->id;
     }
     Redirect::to('/', array('message' => 'Login successful!'));
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['kayttajanimi'], $params['salasana']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Väärä käyttäjätunnus tai salasana!', 'kayttajanimi' => $params['kayttajanimi']));
     } else {
         $_SESSION['user'] = $user->kayttaja_id;
         Redirect::to('/', array('message' => 'Tervetuloa takaisin ' . $user->kayttajanimi . '!'));
     }
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         Redirect::to('/user/login', array('errors' => array('Invalid username or password'), 'attr' => $_POST));
     } else {
         $_SESSION['user'] = $user->id;
         Redirect::to('/', array('message' => 'Welcome back ' . $user->name . '!'));
     }
 }
Example #14
0
 public function run($username, $password)
 {
     global $session;
     $userReg = User::authenticate($username, $password);
     if ($userReg) {
         $session->login($userReg);
         return true;
     } else {
         return false;
     }
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Väärä käyttätunnus tai salasana', 'username' => $params['username']));
     } else {
         $_SESSION['user'] = $user->id;
         Redirect::to('/memo', array('message' => 'Tervetuloa takaisin ' . $user->name . '.'));
     }
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Wrong username or password!', 'username' => $params['username']));
     } else {
         $_SESSION['user'] = $user->id;
         Redirect::to('/', array('message' => 'Welcome back ' . $user->username . '!'));
     }
 }
 public static function login()
 {
     $params = $_POST;
     $user = User::authenticate($params['email'], $params['password']);
     if (!$user) {
         Redirect::to('/', array('login_error' => 'Wrong email or password'));
     } else {
         $_SESSION['user'] = $user->id;
         Redirect::to('/units', array('message' => 'Welcome ' . $user->first_name . "!"));
     }
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         $errors = array();
         $errors[] = 'Väärä käyttäjätunnus tai salasana!';
         View::make('user/login.html', array('errors' => $errors, 'username' => $params['username']));
     } else {
         self::login_and_redirect_to_home_page($user);
     }
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['nimi'], $params['salasana']);
     if (!$user) {
         View::make('user/login.html', array('message' => "Väärä käyttäjätunnus tai salasana!"));
     } else {
         $_SESSION['user'] = $user->nimi;
         //      self::get_user_logged_in();
         Redirect::to('/user/tervetuloa');
     }
 }
Example #20
0
 function index()
 {
     if (isset($_POST['login'])) {
         $result = User::authenticate();
         $location = APP_URL . '/admin';
         if ($result) {
             header("Location: {$location}");
         }
     }
     $this->template('content', 'loginForm.phtml');
     $this->show('main.tpl');
 }
Example #21
0
 function test_authenticate()
 {
     //Arrange
     $name = "Bob";
     $email = "*****@*****.**";
     $test_user = new User($name, $email);
     $test_user->save();
     //Act
     $result = User::authenticate($email);
     //Assert
     $this->assertEquals($test_user, $result);
 }
 /**
  * user authentication.
  */
 protected function POST_login()
 {
     $user = User::authenticate($_REQUEST['email'], $_REQUEST['cleartext']);
     if (is_null($user)) {
         $this->flash['error'] = t("Bad email or password.");
     } else {
         User::current_is($user);
         $this->flash['success'] = sprintf(t('Welcome back %s!'), h($user->fullname));
         global $router;
         $this->view->redirect_to($router->root_url());
     }
 }
Example #23
0
 /**
  * Display method
  *
  * @access public
  */
 public function display()
 {
     if (isset($_POST['username']) and isset($_POST['password'])) {
         try {
             $user = \User::authenticate($_POST['username'], $_POST['password']);
             $_SESSION['user'] = $user;
             Session::redirect('/');
         } catch (\Exception $e) {
             Template::get()->assign('error', true);
         }
     }
 }
Example #24
0
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Wrong username or password', 'username' => $params['username']));
     } else {
         $_SESSION['user'] = $user->id;
         //Kint::dump($user);
         Redirect::to('/', array('message' => 'Welcome back ' . $user->username . '. Start by creating a project if you dont have any yet, add tasks after that! The delete task-button is only visible if you click on the task'));
     }
 }
 public function authenticate()
 {
     $user = new User();
     if ($user->authenticate($this->username, $this->password)) {
         $this->_id = $user->userID;
         $this->setState('employeeID', $user->getEmployeeID());
         $this->setState('fullName', $user->getFullName());
         $this->errorCode = self::ERROR_NONE;
     } else {
         $this->errorCode = self::ERROR_UNKNOWN_IDENTITY;
     }
     return $this->errorCode == self::ERROR_NONE;
 }
 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['email'], $params['password']);
     if (!$user) {
         flash()->error(':(', 'Login failed');
         View::make('login.html', array('email' => $params['email']));
     } else {
         $_SESSION['user'] = $user->id;
         flash('Hey!', 'Nice to see you again');
         Redirect::to('/');
     }
 }
Example #27
0
 public function login($username, $password)
 {
     if ($user = User::authenticate($username, $password)) {
         // user just logged in, update login time.
         $user->lastLogin(time());
         $_SESSION['username'] = $user->username;
         $_SESSION['user_id'] = intval($user->user_id);
         $online = Friend::of($user->user_id);
         return array('r' => 'logged in', 's' => session_id(), 'f' => $online);
     } else {
         return array('r' => 'error', 'e' => 'invalid user');
     }
 }
 /**
  * Login a user
  *
  * @param string $email     Email address
  * @param string $password  Password
  * @return boolean          true if the new user record was saved successfully, false otherwise
  */
 public function login($email, $password)
 {
     $user = User::authenticate($email, $password);
     if ($user !== null) {
         $this->_currentUser = $user;
         // Store the user ID in the session
         $_SESSION['user_id'] = $user->id;
         // Regenerate the session ID to prevent session hijacking
         session_regenerate_id();
         return true;
     }
     return false;
 }
Example #29
0
 public function authenticate()
 {
     try {
         $this->user = User::authenticate($this->username, $this->password);
         return $this->createResult(Zend_Auth_Result::SUCCESS);
     } catch (Exception $e) {
         if ($e->getMessage() == User::NOT_FOUND) {
             return $this->createResult(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, array(self::NOT_FOUND_MSG));
         }
         if ($e->getMessage() == User::WRONG_PWD) {
             return $this->createResult(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(self::BAD_PW_MSG));
         }
     }
 }
Example #30
0
 public function authenticateUsingPostedVars()
 {
     $UserInstance = new User();
     $login = @$this->Controller->params['ak_login'];
     try {
         $result = $UserInstance->authenticate(@$login['login'], @$login['password']);
     } catch (RecordNotFoundException $e) {
         if (!empty($this->Controller->params['ak_login'])) {
             $this->Controller->flash['error'] = $this->t('Invalid user name or password, please try again');
         }
         $this->redirectToSignInScreen();
     }
     return $result;
 }