Ejemplo n.º 1
0
 public function login()
 {
     // login or add user, then log in
     // user details may come from different poviders, etc facebook
     // returns details for a session
     $user = null;
     $error = '';
     $info = '';
     $debug = '';
     $create = 0;
     $provider = 'self';
     $user_name = '';
     $password = '';
     isset($_POST['provider']) && ($provider = $_POST['provider']);
     isset($_POST['user_name']) && ($user_name = $_POST['user_name']);
     isset($_POST['password']) && ($password = $_POST['password']);
     isset($_POST['create']) && ($create = $_POST['create']);
     // login requests from providers other than 'self' have already been authenticated
     // if 'self', then user_name and password are required
     !$this->is_provider($provider) && ($error = 'Invalid login request');
     strlen($error) < 1 && strlen($user_name) < 1 && ($error = 'Please, enter a user name or an email address');
     $provider == 'self' && strlen($error) < 1 && strlen($password) < 1 && ($error = 'Please, enter a password');
     if (strlen($error) < 1) {
         $u = new User_model($this->template, $this->query_string);
         $res = $u->find_user(null, $provider, $user_name);
         $error = $res["errors"][0]["message"];
         $info = $res["info"];
         DEBUG > 0 && ($debug = "login > find_user: "******"errors"][0]["debug"]);
         strlen($error) < 1 && ($user = $res["data"]);
         // users authenticated from other sites are added automatically
         // for 'self', the 'create' POST param must be set to create an account
         if (strlen($error) < 1 && (is_null($user) || count($user) < 1) && ($create == 1 || $provider != 'self')) {
             // visit log is required for this
             $res = $u->add_user($provider, $user_name, $password);
             $error = $res["errors"][0]["message"];
             $info .= strlen($info) > 0 ? "; " . $res["info"] : $res["info"];
             DEBUG > 0 && ($debug .= "; login > add_user: "******"errors"][0]["debug"]);
             strlen($error) < 1 && ($user = $res["data"]);
         }
     }
     if (strlen($error) < 1 && count($user) > 0) {
         // if provider is self, then autenticate password
         if ($provider == 'self') {
             !$this->is_equal($password, $user["password"]) && ($error = "Sorry the user name and password supplied did not match");
         }
         if (strlen($error) < 1) {
             $res = $this->login_user($user);
             $error = $res["errors"][0]["message"];
             $info .= strlen($info) > 0 ? "; " . $res["info"] : $res["info"];
         }
     }
     $result = array('errors' => array(array('message' => $error, 'debug' => $debug)), 'data' => $user, 'info' => $info);
     strlen($info) > 0 && $this->template->flash($info, "alert alert-success");
     $this->template->assign("login", $result);
     return true;
 }
Ejemplo n.º 2
0
 private function setup_admin()
 {
     // set up admin if admin details were passed in config
     $error = "";
     $debug = "";
     $info = "An admin account was not set up because a valid sys admin email was not configured. Please, register an account normally and set rights manually in table user_details to 80 in the database.";
     $email = $this->admin_email;
     $name = $this->admin_name;
     strlen($name) < 1 && ($name = "Tracker Admin");
     $user = array();
     if (strlen($email) > 0 && filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $password = $this->codify($email);
         $u = new User_model($this->template, $this->query_string);
         $res = $u->add_user('self', $email, $password, $name, 10);
         $error = $res["errors"][0]["message"];
         DEBUG > 1 && ($debug = $res["errors"][0]["debug"]);
         strlen($error) < 1 && !is_null($res) && isset($res["data"]) && ($user = $res["data"]);
         strlen($error) < 1 && count($user) < 1 && ($error = "Attempt to create an admin account may have failed.");
         if (strlen($error) > 0) {
             $info = "Please check the database and see if the admin user configured was added. If so, set their rights manually in table user_details to 80 and use the forgotton password feature to log in.";
         } else {
             // attempt to set rights
             $data = array("rights" => 80);
             $res = $this->update('user_details', $data, $user["id"], true, 'user_id', null);
             $error = $this->db_error;
             DEBUG > 0 && ($debug = $this->db_debug);
             if (strlen($error) > 0) {
                 $info = "Attempt to set admin rights may have failed. Please set rights manually in table user_details to 80 and use the forgotton password feature to log in.";
             } else {
                 // success !
                 $info = "An admin account was set up successfully. Please use the 'Forgot password' feature to set your password if needed.";
             }
         }
     }
     strlen($error) > 0 && ($error = "Setup Admin user error: " . $error);
     $result = array('errors' => array(array('message' => $error, 'debug' => $debug)), 'data' => array('admin_name' => $name), 'info' => $info);
     return $result;
 }