Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- class SigninController extends Controller {
- public function _init() {
- global $config;
- if (!$_SESSION['branch']) {
- $model = new Model_EmmaBranch();
- $branch = $model->getBranch($config['branch']);
- $_SESSION['branch'] = $branch;
- }
- $this->layout->name = "Login";
- $this->layout->title = "Login";
- if ($_SESSION['user']) {
- $this->_redirect(BASE_URL);
- } else {
- $user = $_COOKIE['user'];
- if ($user) {
- $model = new Model_Azuser();
- $json = base64_decode($user);
- $arr = json_decode($json);
- $client = $model->getByEmail($arr->email);
- if ($client['password'] == $arr->password) {
- $_SESSION['user'] = $client;
- $this->_redirect(BASE_URL);
- } else {
- setcookie('user', "", 0, "/");
- }
- }
- }
- }
- public function indexAction() {
- if ($_POST) {
- $email = trim($_POST['email']);
- $password = trim($_POST['password']); //6 - 100 ky tu
- $remember = trim($_POST['remember']);
- $r = -1; //chua thiet lap
- if ($r == -1) {
- $model = new Model_Azuser();
- $client = $model->getByEmail($email);
- //$client = $model->getByEmail($email);
- if (!$client) {
- //Wrong email or password
- $r = 2;
- $msg = 'Wrong email or password.';
- }
- }
- if ($r == -1) {
- //check password
- if ($client['password'] != md5($password)) {
- //Wrong email or password
- $r = 2;
- $msg = 'Wrong email or password.';
- }
- }
- if ($r == -1) {
- $_SESSION['user'] = $client;
- //$model->update(array('lastVisitTime' => time()), $email);
- $r = 0;
- if($remember == "true"){
- $json = json_encode(array(
- 'email' => $client['email'],
- 'password' => $client['password']
- ));
- setcookie('user', base64_encode($json), time() + (60 * 60 * 24 * 7), "/");
- }
- }
- if ($this->_isAjaxRequest()) {
- $this->setNoRender();
- $res = array(
- 'r' => $r,
- 'msg' => $msg,
- );
- echo json_encode($res);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement