Example #1
0
function ajax_calls($method, $data)
{
    $user = new User();
    switch ($method) {
        case 'fb_reg':
            $res = $user->login($data);
            if ($res != 0) {
                unset($_SESSION['gplusdata']);
                $_SESSION['user_id'] = $res;
                $_SESSION['email_id'] = $data['email'];
                $url = 'php_script.php';
            } else {
                $url = '';
            }
            echo $url;
            break;
        case 'gp_reg':
            $res = $user->login($data);
            if ($res != 0) {
                unset($_SESSION['fb_id']);
                $_SESSION['user_id'] = $res;
                $_SESSION['email_id'] = $data['email'];
                $url = 'php_script.php';
            } else {
                $url = '';
            }
            echo $url;
            break;
    }
}
 function login()
 {
     if (trim($_POST['token']) != '') {
         $model = new User();
         $confirm = $model->loginza();
         if ($confirm == 'ok') {
             View::$layout = 'popup';
             View::render('registration/popupclose');
         } else {
             $this->redirect('/registration/ask/');
         }
     } else {
         $model = new User();
         $error = $model->login();
         if ($error) {
             $this->redirect('/registration/showlogin/?error');
         } else {
             if (strpos($_SERVER['HTTP_REFERER'], '/registration/showlogin/') !== false) {
                 $this->redirect('/cabinet/');
             } else {
                 $this->redirect($_SERVER['HTTP_REFERER']);
             }
         }
     }
 }
Example #3
0
 public function actionLogin()
 {
     $email = '';
     $password = '';
     $remember = '';
     if (isset($_POST['submit'])) {
         $email = FunctionLibrary::clearStr($_POST['email']);
         $password = FunctionLibrary::clearStr($_POST['password']);
         if (isset($_POST['remember'])) {
             $remember = FunctionLibrary::clearStr($_POST['remember']);
         }
         $errors = array();
         if (!User::checkEmail($email)) {
             $errors[] = 'Невалидный email.';
         }
         $user = User::login($email, $password, $remember);
         if ($user) {
             User::auth($user);
             FunctionLibrary::redirectTo('/cabinet');
         } else {
             $errors[] = 'Неправильные данные для входа на сайт.';
         }
     }
     require_once ROOT . '/views/user/login.php';
     return true;
 }
Example #4
0
 public function hand_registration()
 {
     try {
         $db = new PDO("mysql:dbname=xuthulu", 'root', 'password');
         if (isset($_POST['username']) || isset($_POST['sup_zip_code']) || isset($_POST['sup_city']) || isset($_POST['sup_email']) || isset($_POST['sup_pass'])) {
             $userService = new User($db, $_POST['sup_email'], $_POST['sup_pass']);
             try {
                 $userService->set_email($_POST['sup_email']);
                 $userService->set_username($_POST['username']);
                 $userService->set_city($_POST['sup_city']);
             } catch (Exception $e) {
                 echo "Error: {$e->getMessage()}";
             }
             // Create user
             $userService->sign_up();
             // Create the user session
             if ($user_id = $userService->login()) {
                 $userData = $userService->getUser();
                 header("Location:userpage.php");
             }
         }
     } catch (Exception $e) {
         echo "Error: {$e->getMessage()}";
     }
 }
Example #5
0
 public function actionLogin()
 {
     if (Rays::isLogin()) {
         $this->redirectAction('user', 'home');
     }
     $this->layout = 'user_ui';
     $data = array();
     if (Rays::isPost()) {
         $login = User::login($_POST);
         if ($login instanceof User) {
             Rays::app()->login($login);
             if (!isset($_POST['returnURL'])) {
                 $this->redirect(RHtml::siteUrl("user/home"));
             }
             if (!in_array(Rays::router()->getRouteUrl(RHtml::internalUrl($_POST['returnURL']))['controller'], $this->loginRedirect)) {
                 $this->redirect(RHtml::siteUrl("user/home"));
             }
             $this->redirect($_POST['returnURL']);
         } else {
             $data['loginForm'] = $_POST;
             if (isset($login['verify_error'])) {
                 $this->flash('error', $login['verify_error']);
             }
             $data['validation_errors'] = isset($login['validation_errors']) ? $login['validation_errors'] : null;
         }
     }
     $this->setHeaderTitle("Login");
     $this->addCss('/public/css/form.css');
     $this->render('login', $data, false);
 }
 public function login()
 {
     $data = Request::only('email', 'password');
     $data['password'] = md5($data['password']);
     $rules = array('email' => 'required|email', 'password' => 'required|alphaNum|min:6');
     $validator = Validator::make($data, $rules);
     $result = array('errors' => '', 'result' => '');
     if ($validator->fails()) {
         $messages = $validator->messages();
         foreach ($messages->all() as $message) {
             $result['errors'] .= "<li>{$message}</li>";
         }
         return json_encode($result);
     }
     $user = new User();
     $response = $user->login($data);
     if ($response['status'] === true) {
         $sessionData = array();
         $sessionData['id'] = $response['id'];
         $sessionData['email'] = $response['email'];
         $result['result'] = 'success';
         Session::put('user_data', $sessionData);
     } else {
         $result['errors'] = 'Username or password incorrect. Please try again';
     }
     return json_encode($result);
 }
Example #7
0
 public function check()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     $conn = Db::getConnection();
     $sql = "SELECT username, password, admin\n\t\t\t\tFROM users\n\t\t\t\tWHERE username = '******'";
     $q = $conn->prepare($sql);
     $q->execute();
     $users = $q->fetch(\PDO::FETCH_ASSOC);
     //var_dump($users);die('  proba');
     $logger = new Logger();
     $error = $logger->checkCredentials($password, $users);
     //$isAdmin = $logger->checkAdmin($password,$users);
     //var_dump($error);die('   ajde vise!!!');
     if ($error) {
         //echo '<pre>'; var_dump($error);die(); echo '</pre>';
         $html = new Html($this->controllerName);
         $html->error = $error;
         //echo '<pre>'; var_dump($html->error);die(); echo '</pre>';
         $html->render('index');
     } else {
         $user = new User($users['username'], $users['admin']);
         $user->login();
         //var_dump($user);die('   jebem li ga');
         header('Location: /');
     }
 }
Example #8
0
 public function testLogin2()
 {
     $u = new User();
     $u2 = $u->login('*****@*****.**', 'calpalyn');
     #objp($u2);
     $this->assertEquals($u2->first_name, 'admin');
 }
Example #9
0
 /**
  * log in a user
  * @return string
  */
 public function login()
 {
     //login in our member usig the logic in the parent class.
     $message = parent::login();
     //add some member-spcific logic
     return $message . '... set a flag in the online members table';
 }
 private function initLogin($user, $pass)
 {
     $userModel = new User();
     $userId = $userModel->login($user, $pass);
     $_SESSION['id'] = $userId;
     header("Location: profile");
 }
 /**
  * Log in a user
  * @return string
  */
 public function login()
 {
     //Login in our member using in the parent class.
     $message = parent::login();
     //Add some member-spesific logic
     return $message . '... Set a flag in the online members table';
 }
 /**
  * Log in a user
  * @return string
  */
 public function login()
 {
     // Login in our member using the logic in the parent class.
     $message = parent::login();
     // Add some administrator-spcific logic
     return $message . ' ... log this action in an administrator\'s table';
 }
Example #13
0
 public function __construct()
 {
     if (User::isLogin() === false and !empty($_POST["username"]) and !empty($_POST["pass"])) {
         $head['title'] = 'GİRİŞ YAPILIYOR';
         $kontrol = User::login($_POST["username"], $_POST["pass"]);
         if ($kontrol) {
             redirect('home', 1);
             exit;
         } else {
             redirect('home', 0, array('uyari' => '<div class="alert alert-info"><strong>HATA!</strong> Giriş İşleminiz başarısız! Lütfen bilgilerinizi kontrol ediniz.</div>'));
         }
     } elseif (User::isLogin() == false) {
         $head['title'] = 'GİRİŞ YAP';
         $head['meta']['author'] = '';
         $bodyVeri["uyari"] = redirectData('uyari');
         $data['head'] = "";
         $data['footer'] = Import::view('footer', '', true);
         $data['body'] = Import::view('login', $bodyVeri, true);
         Import::masterPage($data, $head);
         exit;
     } else {
         $head['title'] = 'Yönetim Paneli';
         $head['meta']['author'] = '';
     }
 }
Example #14
0
 /**
  * @depends testLogin
  */
 public function testLoginFailure()
 {
     $user = User::login($this->username, '', false, true);
     $this->assertFalse($user, 'удалось авторизоваться с пустым паролем');
     $user = User::login($this->username, '123', false, true);
     $this->assertFalse($user, 'удалось авторизоваться с неправильным паролем');
     // $this->fail('message');
 }
Example #15
0
 public function login()
 {
     if (empty($_POST['email']) || empty($_POST['password'])) {
         return false;
     }
     $user = new User();
     return $user->login($_POST['email'], $_POST['password']);
 }
Example #16
0
 public function login($username, $password, $allowEmail = TRUE)
 {
     $login = parent::login($username, $password, $allowEmail);
     if ($login) {
         $this->setKey($password, $this->dbkey);
     }
     return $login;
 }
/**
 * Check to see if user is logged in and if not, redirect them to the login page.
 * If they're logged in, let them proceed.
 */
function login_required()
{
    global $user, $template;
    if (!$user->is_logged) {
        $template->set_msg("You must be logged in to access this section.", false);
        User::login();
        exit;
    }
}
 function dologin()
 {
     $result = User::login($_POST['username'], $_POST['password']);
     if ($result) {
         $this->redirect_to("home");
     } else {
         $this->redirect_to("users/login");
     }
 }
 public function register()
 {
     try {
         $errors = array();
         $success = false;
         $isPost = $this->request->isPost();
         $user = new User();
         try {
             $fb_active = API_Facebook::isActive();
             if ($fb_active) {
                 $fb_user = $user->getFacebookUser(ROOT_HTTP . 'register');
                 if (!empty($fb_user)) {
                     $this->response->redirect(ROOT_HTTP);
                 }
             }
         } catch (Exception $e) {
             $errors['authent'] = $e->getMessage();
         }
         $confirm_email = $this->request->post('confirm_email', '');
         $confirm_password = $this->request->post('confirm_password', '');
         if ($isPost) {
             foreach ($user->getFields() as $key => $value) {
                 try {
                     $user->{$key} = $this->request->post($key, '');
                 } catch (Exception $e) {
                     $errors[$key] = $e->getMessage();
                 }
             }
             if (empty($confirm_email) || strcmp($user->email, $confirm_email) !== 0) {
                 $errors['confirm_email'] = Lang::_('You must confirm your email');
             }
             if (empty($confirm_password) || strcmp($user->password, $confirm_password) !== 0) {
                 $errors['confirm_password'] = Lang::_('You must confirm your password');
             }
             if (empty($errors)) {
                 $user_already_exists = $user->checkAlreadyExists();
                 if ($user_already_exists === true) {
                     $errors['email'] = Lang::_('Email already in use');
                 } else {
                     $user->password = password_hash($user->password, PASSWORD_BCRYPT);
                     $user_id = $user->register();
                     if (!empty($user_id)) {
                         $success = $user->login();
                     } else {
                         $errors['authent'] = Lang::_('Register failed');
                     }
                 }
             }
         }
         $form = $user->getRegisterForm('insert', ROOT_HTTP . $this->lang->getUserLang() . '/user/register', $this->request, $isPost, $errors);
         $vars = array('title' => Lang::_('Register'), 'isPost' => $isPost, 'form' => $form, 'errors' => $errors, 'success' => $success);
     } catch (Exception $e) {
         $vars['debug'] = $e->getMessage();
     }
     return $this->render('authent', $vars);
 }
Example #20
0
 public static function validate_login($username, $password)
 {
     $user = User::find_by_username($username, array('active' => 1));
     if ($user && $user->validate_password($password)) {
         User::login($user->id);
         return $user;
     } else {
         return FALSE;
     }
 }
 public function post()
 {
     if (!($userID = User::login($this->post['username'], $this->post['password']))) {
         $this->status = 403;
         $this->message = "Invalid username or password";
     } else {
         Session::login($userID);
         $this->response = array($this->slug => array('auth_id' => $userID, 'auth_token' => APIController::authToken($userID)));
     }
 }
Example #22
0
 public function auth()
 {
     $auth = User::login();
     echo $auth->loggedIn;
     if ($auth->loggedIn == 1) {
         header('Location: ../../user/profile/' . $auth->username . '/');
     } else {
         header('Location: ../../pages/404/');
     }
 }
Example #23
0
 function checkUser()
 {
     $user = new User();
     try {
         $user->login($_POST);
         $this->result = self::OK;
     } catch (Exception $e) {
         $this->result = $e->getCode();
     }
 }
Example #24
0
 public function loginAjaxAction()
 {
     Zend_Layout::getMvcInstance()->disableLayout();
     try {
         User::login($_POST['email'], $_POST['password']);
         echo 1;
     } catch (Exception $e) {
         echo 0;
     }
     die;
 }
 /**
  * Make sessions for login permission.
  *
  * @return Response
  */
 public function doLogin()
 {
     $data = Input::only(['email', 'password', 'remember']);
     $user = new User();
     try {
         $user->login($data['email'], $data['password'], $data['remember']);
     } catch (ValidationException $errors) {
         return Redirect::route('admin.login.index')->withErrors($errors->getErrors())->withInput();
     }
     return Redirect::intended(URL::route('admin.index'));
 }
 public function test_login_username_exist_but_password_wrong()
 {
     $user = new User();
     try {
         $this->_assert_equals($user->login(self::USERNAME, "asdasd"), LOGIN_PASSWORD_WRONG);
     } catch (Password_Wrong $e) {
         $this->_assert_true(1);
         return;
     }
     $this->_assert_true(0);
 }
Example #27
0
 public function executePassword()
 {
     $mail = mfwRequest::param('email');
     $pass = mfwRequest::param('password');
     $user_pass = UserPassDb::selectByEmail($mail);
     if (!$user_pass || !$user_pass->checkPassword($pass)) {
         return $this->buildErrorPage('invalid email or password');
     }
     User::login($mail);
     return $this->redirectUrlBeforeLogin();
 }
Example #28
0
 public function actionLogin()
 {
     $model = new User('login');
     if (isset($_POST['User'])) {
         $model->attributes = $_POST['User'];
         if ($model->validate() && $model->login()) {
             $this->redirect("?r=app/index");
         }
     }
     $this->layout = "//layouts/login";
     $this->render('login', array('model' => $model));
 }
Example #29
0
 public function add(User $user)
 {
     $query = $this->_db->prepare('INSERT INTO t_user (login, password, created, profil, status)
                             VALUES (:login, :password, :created, :profil, :status)') or die(print_r($this->_db->errorInfo()));
     $query->bindValue(':login', $user->login());
     $query->bindValue(':password', $user->password());
     $query->bindValue(':created', $user->created());
     $query->bindValue(':profil', $user->profil());
     $query->bindValue(':status', $user->status());
     $query->execute();
     $query->closeCursor();
 }
Example #30
0
 public static function LoginByPass($login, $pass)
 {
     $user = UserModel::Login($login, $pass);
     if ($user->id > 0) {
         self::$id = $user->id;
         self::$login = $user->login;
         self::$company_id = $user->companyid;
         $hash = self::NewHash($arr['id']);
         setcookie('userid', $hash, time() + 360000, '/');
         UserModel::update(['hash' => $hash])->id($user->id);
     }
 }