/** * testExists function * @return void */ public function testExists() { $this->loadFixtures('User'); $TestModel = new User(); $this->assertTrue($TestModel->exists(1)); $TestModel->id = 2; $this->assertTrue($TestModel->exists()); $TestModel->delete(); $this->assertFalse($TestModel->exists()); $this->assertFalse($TestModel->exists(2)); }
function email_login($email, $password) { $CI =& get_instance(); $user = new User(); $user->where(array('email' => $email, 'password' => $password))->get(); if ($user->exists()) { if ($user->profile->type == "ประชาชนทั่วไป") { $timediff = timeDiff($user->last_login, date("Y-m-d H:i:s", now())); $webboard_status_config = new Webboard_status_config(1); if ($timediff > $webboard_status_config->memlock) { $user->m_status = "ban"; $user->last_login = $user->last_login; } else { $user->m_status = "active"; $user->last_login = date("Y-m-d H:i:s", now()); } } $user->save(); if ($user->m_status == "ban") { return FALSE; } $_SESSION['id'] = $user->id; // $CI->session->set_userdata('id',$user->id); $_SESSION['level'] = $user->level_id; // $CI->session->set_userdata('level',$user->level_id); //$log = fopen("log.txt", "a"); //fwrite($log, ' '.$user->last_login.' - '.$user->email.' เข้าสู่ระบบ'.'\r\n'); //fclose($log); file_put_contents('log.txt', $user->last_login . ' - ' . $user->email . ' เข้าสู่ระบบ' . "\n", FILE_APPEND); return TRUE; } else { return FALSE; } }
function __construct($user_id = 1) { $user = new User($user_id); if ($user->exists()) { $this->currentUser = $user; } }
/** * Check for not-updated-today, not-deleted keywords * And set for rank update if exist * * daily */ public function queue_keywords_for_update() { $keyword_rank = new Keyword_rank(); $keyword_rank_ids = $keyword_rank->where('date', date('Y-m-d'))->get()->all_to_single_array('keyword_id'); if (empty($keyword_rank_ids)) { $keyword_rank_ids = array(0); } $keywords = new Keyword(); $keywords->where('is_deleted', 0)->where_not_in('id', $keyword_rank_ids)->get(); if (!$keywords->exists()) { log_message('CRON_ERROR', __FUNCTION__ . ' > ' . 'No keywords for rank update'); return; } $acc = $this->getAAC(); foreach ($keywords as $keyword) { $user = new User($keyword->user_id); if (!$user->exists()) { continue; } $acc->setUser($user); if (!$acc->isGrantedPlan('local_search_keyword_tracking')) { continue; } $args = $keyword->to_array(); $this->jobQueue->addJob('tasks/google_rank_task/grabber', $args, array('thread' => self::GOOGLE_RANK_THREAD)); } $ids_str = implode(', ', array_values($keywords->all_to_single_array('id'))); log_message('CRON_SUCCESS', __FUNCTION__ . ' > ' . 'Keywords for rank update ids: ' . $ids_str); return; }
public function inviteUser($userId = null) { if ($userId) { $user = new User($userId); $email = $user->email; } else { $email = $this->input->post('email'); } if ($email) { $group = $this->config->item('admin_group', 'ion_auth'); $adminGroup = $this->ion_auth->getGroupByName($group); $result = $this->ion_auth->invite($email, array($adminGroup->id), $userId); if ($result) { if (!$userId) { $user = new User($result['id']); $user->save(array('manager_user' => new User($this->c_user->id))); } if ($user->exists()) { $sender = $this->get('core.mail.sender'); $params['to'] = $email; $params['data'] = array('link' => site_url('auth/invite/' . $result['code']), 'sitename' => $this->config->config['OCU_site_name']); } } if ($success = $result && $sender->sendInviteMail($params)) { $this->addFlash(lang('invite_success'), 'success'); } else { $this->addFlash(lang('invite_error')); } if ($userId) { redirect('admin/manage_admins'); } echo json_encode(array('success' => $success)); } }
public function log_in() { // backup username for invalid logins $uname = $this->email; // Create a temporary user object $u = new User(); // Get this users stored record via their email $u->where('email', $uname)->where('active', 1)->get(); if (!$u->exists()) { return false; } // Give this user their stored salt $this->salt = $u->salt; // Validate and get this user by their property values, // this will see the 'encrypt' validation run, encrypting the password with the salt $this->validate()->get(); // If the username and encrypted password matched a record in the database, // this user object would be fully populated, complete with their ID. // If there was no matching record, this user would be completely cleared so their id would be empty. if ($this->exists()) { // Login succeeded return TRUE; } else { // Login failed, so set a custom error message //$this->error_message('login', 'Username or password invalid'); // restore username for login field //$this->username = $uname; return FALSE; } }
function _ops_update() { require_login(); $msg = ''; $uid = max(0, intval($_POST['uid'])); $user = new User(); if ($uid) { $user->retrieve($uid); $user->merge($_POST); if (!$user->exists()) { $msg = 'User not found!'; } else { if ($user->update()) { $msg = 'User updated!'; } else { $msg = 'User update failed!'; } } } else { $user->merge($_POST); if ($user->create()) { $msg = 'User inserted!'; } else { $msg = 'User insert failed!'; } } redirect('users/manage', $msg); }
public function update($id, $request) { $config = new Config(CONFIG . 'app.json'); $config->parseFile(); $data = $request->getParameters(); if (isset($data['userSubmit'])) { $deny_fields = ['id', 'rank']; if (User::exists($id)) { $user = User::find($id); foreach ($data as $k => $value) { if (isset($user->{$k}) && !in_array($k, $deny_fields)) { switch ($k) { case 'username': $u_c = $user->getMainChannel(); $u_c->name = $value; $u_c->save(); break; case 'pass': $value = !empty($value) ? password_hash($value, PASSWORD_BCRYPT) : $user->pass; break; } $user->{$k} = $value; } $user->save(); } $r = new ViewResponse("admin/user/edit", ['user' => $user]); } return $r; } }
/** * Daily social statistic collect * Add new access token to Queue * * @access public * @return void */ public function run() { $types = array('facebook', 'twitter', 'linkedin', 'google', 'instagram'); $tokens = Access_token::inst()->where_in('type', $types)->get(); $aac = $this->getAAC(); $acceptedUsersIds = array(); $now = new \DateTime('UTC'); foreach ($tokens as $_token) { $now->modify('1 minutes'); $user = new User($_token->user_id); if (!$user->exists()) { continue; } $aac->setUser($user); if (!$aac->isGrantedPlan('social_activity')) { continue; } $args = $_token->to_array(); foreach ($_token->social_group->get() as $profile) { $args['profile_id'] = $profile->id; if (!in_array($args['user_id'], $acceptedUsersIds) && $args['type'] != 'instagram') { array_push($acceptedUsersIds, $args['user_id']); } } } $this->jobQueue->addJob('tasks/social_reports_task/statistic', $acceptedUsersIds, array('thread' => self::SOCIAL_THREAD)); }
/** * Creates a new user */ function user_put() { /* Check for an existing user ------------------------------------------------- */ $uuid = $this->put('uuid'); $existing_user = new User(); $existing_user->get_by_uuid($uuid); if ($existing_user->exists()) { $output = array('User with UUID ' . $uuid . ' already exists'); } else { // They don't exist, create them $user = new User(); $user->uuid = $uuid; if ($user->save()) { $output = array('User created with UUID: ' . $uuid); log_message('error', 'User created'); } else { $output = array('Error saving user'); log_message('error', 'Error creating user'); } } /* TODO - return dance and robot data here ------------------------------------------------- */ $this->response($output); }
function testUserExistence() { $user = new User(2); $this->assertTrue($user->exists()); $this->assertTrue(!empty($user->name())); $this->assertTrue(!empty($user->pass())); }
/** * Daily social statistic collect * Add new access token to Queue * * @access public * @return void */ public function run() { $types = array('twitter'); $tokens = Access_token::inst()->where_in('type', $types)->get(); $aac = $this->getAAC(); $now = new \DateTime('UTC'); foreach ($tokens as $_token) { $now->modify('1 minutes'); $user = new User($_token->user_id); if (!$user->exists()) { continue; } $aac->setUser($user); if (!$aac->isGrantedPlan('social_activity')) { continue; } $args = $_token->to_array(); foreach ($_token->social_group->get() as $profile) { $args['profile_id'] = $profile->id; //Twitter tasks $this->jobQueue->addJob('tasks/twitter_task/searchUsers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/updateFollowers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/randomRetweet', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/randomFavourite', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/sendWelcomeMessage', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/followNewFollowers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); $this->jobQueue->addJob('tasks/twitter_task/unfollowUnsubscribedUsers', $args, array('thread' => self::SOCIAL_THREAD, 'execute_after' => $now)); } } }
/** * Get a new UsersActivations for a User. * * @param User $user * @return UsersActivations */ public static function factory(User $user) { $ua = new self(); if (!$user->exists()) { throw new RuntimeException(__("Cannot create a user activation for non-existent user.")); } $ua->user_id = $user->id; return $ua; }
public static function login($username, $password) { $userID = self::idByUsername($username); $user = new User($userID); if ($user->exists() && $user->password == self::encryptPassword($password)) { return $user->id; } return false; }
/** * Create a new API framework for a given User * * @param User $u */ public function __construct(User $u) { if (!$u || !$u->exists() || !$u->user_id) { throw new Exception("Invalid user specified!"); } // send User to parent ini $ini = array('user' => $u); parent::__construct(APPPATH . $this->api_path, $this->namespace, $ini); }
/** * Either login or register a user. * @param string $email The user's email address * @return User */ public static function loginOrRegister($email) { // If such a user already exists, return it if (User::exists($email)) { return new User($email); } // Otherwise, create it and return it return User::create($email); }
/** * Find user by email * * @param $email * * @return bool|User */ public static function findByEmail($email) { $user = new User(); $user->get_by_email($email); if ($user->exists()) { return $user; } return false; }
public function index() { $get_user_id = $this->input->get('user_id'); $facebook_user_id = $this->facebook->getUser(); if ($this->user_id && $this->session->userdata('facebook_id')) { redirect('users'); } elseif ($this->user_id) { $user = new User(); $user->where('facebook_id', $facebook_user_id); $user->get(); ////////////////////////////////////////////////// // If the user has not been linked // ////////////////////////////////////////////////// if (!$user->exists()) { // Link the user $user = new User($this->user_id); $user->facebook_id = $facebook_user_id; $user->save(); redirect('fb/link_account'); } else { redirect('fb/link_account'); } } elseif (!$this->user_id && $get_user_id == 'register' && $facebook_user_id) { $facebook_user_info = $this->facebook->api('/me'); $user = new User(); $user->where('email', $facebook_user_info['email']); $user->get(); if ($user->exists()) { //$this->facebook->logout(); $data['error_head'] = 'Error : Existing User'; $data['error_body'] = $this->load->view('content/errors/fb/existing_account', null, TRUE); $data['content'] = 'main/error_page'; $this->load->view('master', $data); } else { $this->load->helper('keygen'); $password = keygen_generate(); $user = new User(); $user->email = $facebook_user_info['email']; $user->firstname = $facebook_user_info['first_name']; $user->lastname = $facebook_user_info['last_name']; $user->facebook_id = $facebook_user_id; $user->password = $password; $user->save(); // TODO : Security on login $this->session->set_userdata('user_id', $user->id); $this->user_id = $user->id; $this->session->set_userdata('facebook_register', TRUE); redirect('users/facebook_register'); } } else { $this->load->helper('form'); $data['content'] = array('main/home'); $this->load->view('master', $data); } }
public function testSaveOnNewRecordusingSetters() { $obj = new User(); $obj->name = 'bob5000'; $obj->my_int = 10000; $this->assertTrue($obj->save()); $this->assertTrue(User::exists('name', 'bob5000')); $this->assertEquals($obj->name, 'bob5000'); $this->assertEquals($obj->my_int, 10000); $obj->destroy(); }
public static function login($userid = '', $password = '', $remember = false) { $user = new User($userid); if (!empty($userid) && !empty($password) && $user->exists()) { if (Hash::checkPassword($password, $user->data()->password)) { self::forceLogin($user, $remember); return true; } } return false; }
public function grabber(array $directory_user) { log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Reviews grabber'); try { $directoryUser = new Directory_User($directory_user['id']); if (!$directoryUser->exists()) { throw new Exception('Directory_User id:' . $directory_user['id'] . ' doesn\'t exist'); } $directory = $directoryUser->directory->get(); if (!$directory->exists()) { throw new Exception('Directory id:' . $directory_user['directory_id'] . ' doesn\'t exist'); } if (!$directory->status) { throw new Exception('Directory id:' . $directory_user['directory_id'] . ' is disabled'); } $link = !empty($directory_user['additional']) ? $directory_user['additional'] : $directory_user['link']; log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Try to grabb - ' . $directory->name); $aac = $this->getAAC(); $user = new User($directory_user['user_id']); if (!$user->exists()) { return; } $aac->setUser($user); $directory_parcer = Directory_Parser::factory($directory->type)->set_url($link); $reviews = $directory_parcer->get_reviews(); /** * Store additional data to */ if ($directory_parcer instanceof Directory_Interface_UserStorage) { $directoryUser->setAdditional($directory_parcer->getDataToStore())->save(); } } catch (Exception $e) { log_message('TASK_ERROR', __FUNCTION__ . ' > ' . 'Reviews: ' . $e->getMessage()); throw $e; } //$today_midnight = strtotime('-7 day midnight'); $today_midnight = strtotime('-14 day midnight'); if (is_array($reviews) && !empty($reviews)) { foreach ($reviews as $_review) { $review_model = new Review(); $review_model->from_array($_review); $review_model->user_id = $directory_user['user_id']; $review_model->directory_id = $directory_user['directory_id']; $review_model->profile_id = $directory_user['profile_id']; $review_model->posted_date = date('Y-m-d', $_review['posted']); $review_model->save(); log_message('TASK_DEBUG', __FUNCTION__ . ' > ' . 'Review saved'); } } }
/** * TC12: Create operation on Users * Test to verify that the database can save new users * The test is performed by creating a user object with the required input fields * Once the test is complete no errors will appear and the user will be in the database */ public function testCreateUser() { //Create the user $user = new User(); $user['username'] = '******'; $user['first_name'] = 'test'; $user['last_name'] = 'test'; $user['password'] = md5('test'); $user['email_address'] = 'test'; $user->save(); //Verify they exist now $this->assertTrue($user->exists()); }
function login($username, $password) { // $password = md5(sha1($password."secret")); $CI =& get_instance(); $user = new User(); $user->where(array('username' => $username, 'password' => $password))->get(); // $user->check_last_query(); if ($user->exists()) { $CI->session->set_userdata('id', $user->id); $CI->session->set_userdata('level', $user->level_id); $CI->session->set_userdata('user_type', $user->user_type_id); return TRUE; } else { return FALSE; } }
function _edit($uid = 0) { require_login(); $user = new User(); $user->retrieve($uid); if (!$user->exists()) { $data['body'][] = '<p>User Not Found!</p>'; } else { $fdata['form_heading'] = 'Edit User'; $fdata['user'] = $user; $form = View::do_fetch(VIEW_PATH . 'users/edit.php', $fdata); $data['head'][] = View::do_fetch(VIEW_PATH . 'users/edit_js.php'); $data['body'][] = '<h2>Edit User</h2>'; $data['body'][] = $form; } View::do_dump(VIEW_PATH . 'layouts/mainlayout.php', $data); }
public function getAssociatedUsers() { $fields = ['one', 'two']; $users = []; foreach ($fields as $field) { if ($this->{'id_' . $field} != null && $this->{'id_' . $field} != '' && $this->{'id_' . $field} != 0) { if (User::exists($this->{'id_' . $field})) { $users[] = User::find($this->{'id_' . $field}); } else { $users[] = null; } } else { $users[] = null; } } return $users; }
function _ops_delete($uid = 0) { require_login(); $msg = ''; $uid = max(0, intval($uid)); $user = new User($uid); if (!$user->exists()) { $msg = 'User not found!'; } else { if ($user->delete()) { $msg = 'User deleted!'; } else { $msg = 'User delete failed!'; } } redirect('users/manage', $msg); }
function do_login() { $u = new User(); $u->where('username', $this->input->post('username'))->or_where('email', $this->input->post('username'))->limit(1)->get(); if ($u->exists()) { if (sha1($_POST['password']) == $u->password) { $this->session->set_userdata(array('id' => $u->id)); redirect('upcoming'); } else { $this->session->set_flashdata('msg', '<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a>Username or password incorrect.</div>'); redirect('login'); } } else { $this->session->set_flashdata('msg', '<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a>Username or password incorrect.</div>'); redirect('login'); } }
public function delete($id) { $user = new User($id); if (!$user->exists()) { $this->message = "User not found"; $this->status = 404; return; } if ($user->id != Session::$user['id']) { $this->message = "Unauthorized"; $this->status = 403; return; } $user->remove(); $this->message = "User removed"; $this->status = 204; }
function _login() { $username = trim($_POST['username']); $password = $_POST['password']; $user = new User(); $user->retrieve_one('username=?', $username); if (!$user->exists()) { unset($_SESSION['authuid']); redirect('main/login/' . $username, 'Login Failed!'); } if ($password != $user->get('password')) { unset($_SESSION['authuid']); redirect('main/login/' . $username, 'Wrong Password!'); } //Login Succeeded $_SESSION['authuid'] = $user->get('uid'); redirect('main', 'Login Successful!'); }
function importFile($file, $meta) { $user = new User(); $name = decodeName($file); $name = preg_replace('/\\s+\\d+$/', "", $name); if ($_REQUEST['group']) { $name = $_REQUEST['group'] . $GLOBALS['pie']['group_delimiter'] . $name; } if ($meta['user']) { // Old style author. $meta['author'] = $meta['user']; unset($meta['user']); } if (!$meta['stamp']) { $meta['stamp'] = filemtime($file); } if (!$meta['type']) { // Determine file type. if (preg_match('/\\.([0-9A-Za-z]{1,5})$/', $name, $match)) { // File type can be determined by file name suffix. $map = new MapFile(); if ($type = $map->read($GLOBALS['pie']['library_path'] . "/share/suffix.map", strtolower($match[1]))) { $meta['type'] = $type; } } elseif (function_exists("mime_content_type")) { $meta['type'] = mime_content_type($file); } } // User mapping. if (!$meta['author'] && $_REQUEST['author']) { $meta['author'] = $_REQUEST['author']; } if (!$user->exists($meta['author']) && $_REQUEST['author']) { $meta['author'] = $_REQUEST['author']; } $temp = pieTempName("_import"); if (!copy($file, $temp)) { return false; } $f = new File(); $f->name = $name; $f->meta = $meta; return $f->write($temp); }