public function setSession($last_checked_message) { Session::set('last_chat_message', $last_checked_message); $u = new MfrUsers(); $u->id = Session::get('id'); $u->last_chat_message = $last_checked_message; $u->save(); }
private static function setLanguage() { if (!Session::get('application-language')) { $lang = get_browser_language(); # Set the language in_array($lang, Config::get('language')['allowed-languages']) ? Session::set('application-language', $lang) : Session::set('application-language', Config::get('language')['default-language']); } include_once ROOT . DS . 'app' . DS . 'languages' . DS . Session::get('application-language') . '.php'; Lang::set($marianaFrameworkLanguageArray); }
public static function getNewChatMessages($conversation_id) { $last_message = Session::get('last-chat-message'); $messages = MfrChatMessages::where('conversation_id', $conversation_id)->also('id', '>', $last_message)->desc()->as_array()->get(); $last_message = $messages[0]['id']; $messages = array_reverse($messages); $i = 0; foreach ($messages as $message) { $u = MfrUsers::find($message['user_id'])[0]; if ($u->avatar == '' || ($u->avatar = null)) { $u->avatar = DEFAULT_IMAGE; } $messages[$i]['user-info'] = $u; $i++; } Session::set('last-chat-message', $last_message); return $messages; }
public function checkRememberMe() { // STEP 1: Check if there is a active session.. if (!isset($_SESSION["id"]) || empty($_SESSION["id"])) { $cookieId = Config::get("cookieID"); //STEP 2: Check for cookie that identifies this session (set at config)... if (isset($_COOKIE[Config::get("cookieID")]) && isset($_COOKIE[Config::get("cookieHash")])) { // STEP 3: Decrypt the hash $decriptedHash = Criptography::decript($_COOKIE[Config::get("cookieHash")]); $confirmation = Sessions::where("id", $_COOKIE[Config::get("cookieID")])->also("hash", $decriptedHash)->first(); // STEP 4: if exists in the database: $setSession = json_decode($confirmation["json_session"]); foreach ($setSession as $key => $pair) { Session::set($key, $pair); } } } }
public function login($params = array()) { $this->load(); $this->status['status'] = 'fail'; if (!Session::csrf($params['mariana-csrf'])) { $this->status['errors'] = array(Lang::get('csrf-check-fail')); return $this->return_json($this->status); } $creds = array(); $creds['user_login'] = $params['username']; $creds['user_password'] = $params['password']; $creds['remember'] = true; $user = wp_signon($creds, false); if (is_wp_error($user)) { $this->status['errors'] = array(Lang::get('login-errors')); return $this->return_json($this->status); } else { $u = MfrUsers::find($user->ID)[0]; Session::set('id', $user->ID); Session::set('nice_name', $user->user_nicename); Session::set('first_name', $user->user_firstname); Session::set('last_name', $user->user_lastname); Session::set('email', $user->user_email); Session::set('level', $u->level); Session::set('gender', $u->gender); Session::set('coach', $u->coach); Session::set('active', $u->active); # Get user info: wp_set_auth_cookie($user->ID, 0, 0); $ip = mfr_get_ip(); $date = time(); $sql = 'INSERT INTO `mfr_user_login` ( `date`, `ip`, `user_id`) VALUES ( ?, ?, ?);'; $stmt = Framework\Database::getConnection()->prepare($sql); $stmt->bindParam(1, $date); $stmt->bindParam(2, $ip); $stmt->bindParam(3, $user->ID); $stmt->execute(); $this->status['status'] = 'ok'; } return $this->return_json($this->status); }
public function first_report($params = array()) { $this->resetStatus(); $inputs = array('objective' => array('name' => 'objective', 'required' => true, 'number' => true), 'gender' => array('name' => 'gender', 'required' => true, 'number' => 3), 'height' => array('name' => 'height', 'required' => true, 'number' => true), 'weight' => array('name' => 'weight', 'required' => true, 'number' => true), 'neck' => array('name' => 'neck', 'required' => true, 'number' => true), 'waist' => array('name' => 'waist', 'required' => true, 'number' => true), 'improvaments' => array('name' => 'improvements', 'alfanum' => true), 'extras' => array('name' => 'extras', 'alfanum' => true)); if ($_POST['gender'] == 2) { $inputs['hip'] = array('required' => true, 'numeric' => true); } $v = Validation::check($inputs); if ($v == false) { $this->status['errors'] = Flash::showMessages(); $this->return_json($this->status); return false; } else { $r = new MfrUserReport(); $r->last_updated = time(); $r->user_id = Session::get('id'); $r->height = $params['height']; $r->weight = $params['weight']; $r->neck_measurement = $params['neck']; $r->waist_measurement = $params['waist']; $r->waist_measurement = $params['waist']; $r->hip_measurement = $params['hip']; $r->waist_measurement = $params['waist']; $r->observations = $params['extras']; $r->save(); $u = new MfrUsers(); $u->id = Session::get('id'); $u->gender = $params['gender']; $u->last_updated = time(); $u->objective = $params['objective']; $u->weak_points = $params['improvements']; $u->other_requirements = $params['extras']; $u->save(); Session::set('gender', $params['gender']); $this->status['success'] = 'ok'; } return $this->return_json($this->status); }