public function setFirst() { // 获取要赠送的短信的条数 $sms_count = 0; $fields = array(); // 如果还没设置过信息,则进行设置,并送短信 foreach ($this->_support as $field => $smsCount) { $this->_field = $field; if (!$this->hasSet() && $this->_support[$this->_field] > 0) { $sms_count += $smsCount; $fields[] = $field; } } if ($sms_count > 0) { // 赠送短信,并发送通知 $user = User_Model::instance(); $smsUpdateStr = $this->smsUpdateStr(); $content = '您好,这是您第一次设置' . $smsUpdateStr . ',系统赠送了' . $sms_count . '条短信给您'; // echo $content; try { // @todo 应该支持事务操作 $updated = $this->updateField($fields); $user->present_sms($this->_uid, $sms_count, $content, false); } catch (Exception $e) { } } return $sms_count; }
public function editValidate($data = array()) { $getUser = $this->getId('', $data['name']); //check user exists if ($getUser) { if (!empty($data['id'])) { // Case : Edit User if ($getUser['id'] != $data['id']) { self::$error['name'] = 'Username already exists !Please enter a different username!'; } } else { // Case : Add User self::$error['name'] = 'Username already exists !Please enter a different username!'; } } $dataValidate = array('name' => $data['name'], 'password' => $data['password'], 'email' => $data['email']); $this->validate->dataValidate($dataValidate); self::$error = array_merge($this->validate->getError(), self::$error); if (!$this->validate->fileValidate()) { self::$error['file'] = "File must have ( gif , jpeg , jpg , png ) type"; } if (isset(self::$error['name']) || isset(self::$error['password']) || isset(self::$error['email']) || isset(self::$error['file'])) { if (!empty(self::$error['name']) || !empty(self::$error['password']) || !empty(self::$error['email']) || !empty(self::$error['file'])) { return false; } } return true; }
public function __construct($request) { parent::__construct($request); $this->templateDirectory = realpath(dirname(__FILE__) . "/../template") . "/"; $this->template = "itemEdit.html.php"; $UserModel = new User_Model(); $this->component = "menu"; $itemId = $request->get("itemId"); if (empty($itemId)) { $this->action = "insert"; } else { $this->action = "update"; } $this->aItemSelect = DKY_Item::getItems(null, true); if (empty($itemId) && !empty($_SESSION["aBlock"][$this->block_id]["itemId"])) { $itemId = $_SESSION["aBlock"][$this->block_id]["itemId"]; } if (empty($itemId) || $this->action == "insert") { $this->action = "insert"; $this->aItem = null; unset($_SESSION["aBlock"][$this->block_id]["itemId"]); } else { $_SESSION["aBlock"][$this->block_id]["itemId"] = $itemId; $this->aItem = DKY_Item::getItemById($itemId); $this->action = "update"; unset($this->aItemSelect[$itemId]); // Can't select itself as a parent. } $this->aGroups = $UserModel->getGroups(true); $this->getItemsURL = DKY_HTTP::makeURL($request->aURL["path"], "menu", "get_items"); $this->cancelURL = DKY_HTTP::makeURL($request->aURL["path"], "menu", "list_items"); }
function play_game($shotbox) { $usuario = new User_Model(); $toView["view"] = 'battlefield_view'; $toView["userHit"] = $this->user_play($shotbox); $toView["fired"] = $this->sesion->obtener('fired'); if ($this->check_player() == 1) { $id = $this->sesion->obtener('id'); $usuario->won($id); $usuario->finished($id); $usuario->avgMoves($id, $tries); $usuario->setRanking($id); $toView["enemyFleet"] = $this->sesion->obtener('enemyFleet'); $toView["winner"] = 1; $toView["userHits"] = $this->sesion->obtener('userHits'); $toView["enemyHits"] = $this->sesion->obtener('enemyHits'); $toView["view"] = "results_view"; return $toView; } $toView["enemyHit"] = $this->enemy_play(); $toView["userFleet"] = $this->sesion->obtener('userFleet'); if ($this->check_enemy() == 1) { $id = $this->sesion->obtener('id'); $usuario->lost($id); $usuario->finished($id); $usuario->setRanking($id); $toView["enemyFleet"] = $this->sesion->obtener('enemyFleet'); $toView["winner"] = 2; $toView["userHits"] = $this->sesion->obtener('userHits'); $toView["enemyHits"] = $this->sesion->obtener('enemyHits'); $toView["view"] = 'results_view'; return $toView; } return $toView; }
public function create() { $this->template->content = new View('users/create'); $form = new Validation($_POST); $form->pre_filter('trim', true); $form->add_rules('username', 'required')->add_rules('password', 'required')->add_rules('email', 'required', 'valid::email'); $this->template->content->repopulate = $form; if ($form->validate()) { // Create new user $user = new User_Model(); if (!$user->username_exists($this->input->post('username'))) { foreach ($form->as_array() as $key => $val) { // Set user data $user->{$key} = $val; } if ($user->validate($form->as_array())) { if ($user->add(ORM::factory('role', 'login')) and $user->save()) { // Redirect to the login page url::redirect('login'); } } } } // Error $this->template->content->error = $form->errors('login'); }
function p_delete_action($id) { $post_Model = new User_Model(); $post_Model->delete_post($id); $posts = $post_Model->get_all_posts(); require "view/template/user/admin.php"; }
public function get_by_id($id) { $user_model = null; //DATABASE CONNECTION $this->db->connect(); //SELECT BY ID $sql = "SELECT * FROM user WHERE user_id=?"; //PREPARE $stmt = $this->db->initialize($sql); //BIND $stmt->bind_param("i", $id); //EXECUTE $stmt->execute(); //BIND RESULT $stmt->bind_result($user_id, $user_name, $first_name, $last_name, $contact_number, $user_type, $user_status, $user_hash); while ($stmt->fetch()) { //instantiate object $user_model = new User_Model(); $user_model->set_user_id($user_id); $user_model->set_user_name($user_name); $user_model->set_first_name($first_name); $user_model->set_last_name($last_name); $user_model->set_contact_number($contact_number); $user_model->set_user_type($user_type); $user_model->set_user_status($user_status); $user_model->set_user_hash($user_hash); } $this->db->close(); return $user_model; }
public function run() { try { $m_user = new User_Model(); $view = new Login_View(); $view->setparm('pagetitle', "用户登录" . $TITLE_SUFFIX); //TODO:反注入 //TODO:验证码 try { if (isset($_POST['username'])) { $userid = $m_user->getuserid($_POST['username']); switch ($m_user->checkpassword($userid, $_POST['password'])) { case $m_user::CHECKPWD_ACCEPTED: session_start(); $_SESSION['userid'] = $userid; $_SESSION['expiretime'] = time() + $SESSION_ADD_TIME; $_SESSION['absexpiretime'] = time() + $_POST['vaildtime']; header("Location: " . $MAIN_PAGE_URL); break; case $m_user::CHECKPWD_DENIED: throw new AuthFailed($TXT_PASSWORD_ERROR); break; case $m_user::CHECKPWD_RESTRICTED: throw new AuthFailed($TXT_USER_RESTRICTED); } } } catch (AuthFailed $e) { $view->setparm('errormsg', $e->getMessage()); } } catch (ResourceFailed $e) { $view->setparm('errormsg', $e->getMessage()); } $view->render(); }
function staff($id, $display = 'week') { $um = new User_Model(); $um->get_by_id($id); if (!$um->exists()) { return; } $this->data['object'] = $um; $um->shift->where('status', SHIFT_MODEL::STATUS_ACTIVE); /* find min and max date */ $max_date = $um->shift->select_max('date')->get()->date; $min_date = $um->shift->select_min('date')->get()->date; $shifts = $um->shift->get_iterated(); /* compile dates */ $dates = array(); $date = $min_date; $this->hc_time->setDateDb($date); switch ($display) { case 'week': $this->hc_time->setStartWeek(); break; case 'month': $this->hc_time->setStartMonth(); break; } $date = $this->hc_time->formatDate_Db(); while ($date <= $max_date) { switch ($display) { case 'week': $start = $this->hc_time->formatDate_Db(); $this->hc_time->setEndWeek(); $end = $this->hc_time->formatDate_Db(); break; case 'month': $start = $this->hc_time->formatDate_Db(); $this->hc_time->setEndMonth(); $end = $this->hc_time->formatDate_Db(); break; } $dates[$start . '-' . $end] = array('shift_count' => 0, 'shift_duration' => 0, 'timeoff_count' => 0, 'timeoff_duration' => 0); $this->hc_time->modify('+1 day'); $date = $this->hc_time->formatDate_Db(); } foreach ($shifts as $sh) { reset($dates); foreach (array_keys($dates) as $dk) { list($start, $end) = explode('-', $dk); if ($sh->date >= $start && $sh->date <= $end) { $dates[$dk]['shift_count']++; $dates[$dk]['shift_duration'] += $sh->get_duration(); } } } $this->data['dates'] = $dates; $this->data['display'] = $display; // $this->conf['path'] = 'admin/users'; $this->set_include('edit/stats', 'admin/users'); $this->load->view($this->template, $this->data); }
/** * This method will handle the signup process * */ function signUp() { $json_data = json_decode(file_get_contents('php://input')); $data = array('name' => $json_data->{'username'}, 'email' => $json_data->{'email'}, 'password' => $json_data->{'password'}, 'privilages' => 2); $this->load->model('User_Model'); $user_model = new User_Model(); $isAdded = $user_model->addNewUser($data); echo json_encode(array("status" => $isAdded)); }
public function setup() { $user = new User_Model(); $user->email = '*****@*****.**'; $user->username = '******'; $user->password = '******'; $user->roles = array(new Role_Model(1)); $user->save(); }
public function get_all() { //ARRAY OBJECT HARU PASS GARNA $user_list = array(); //DATABASE CONNECTION $this->db->connect(); //SELECT ALL QUERY $sql = "SELECT user_id,user_name,first_name,last_name,contact_number,user_type,user_status,gen_id,age FROM user INNER JOIN generaluser ON user_id = u_id"; //fetchquery $result = $this->db->fetchquery($sql); //STORE IN OBJECT AND SEND TO VIEW while ($row = $result->fetch_assoc()) { $user_model = new User_Model(); $user_model->set_user_id($row['user_id']); $user_model->set_user_name($row['user_name']); $user_model->set_first_name($row['first_name']); $user_model->set_last_name($row['last_name']); $user_model->set_contact_number($row['contact_number']); $user_model->set_user_type($row['user_type']); $user_model->set_user_status($row['user_status']); array_push($user_list, $user_model); } $this->db->close(); return $user_list; }
/** * View all registered users * * @access public * @return string Returns XML containing list of all users or error message */ public function list_all() { if (apiler::is_authorized()) { $users = new User_Model(); $list = $users->list_all_users(); $view = new View('api/user_list'); $view->list = $list; $view->render(true); } else { apiler::not_authorized(); } }
public function createObjectFromData($row) { //Create a new user_model object $user = new User_Model(); //Set the ID on the user model $user->setId($row->id); //Set the username on the user model $user->setUsername($row->username); //Set the password on the user model $user->setPassword($row->password); //Return the new user object return $user; }
public function insert($category, $username, $value) { $cat = new Category_Model(); $category = $cat->get_id($category); $user = new User_Model(); $username = $user->get_id($username); $results = $this->db->query("INSERT INTO results SET cat_id = ?, user_id = ?, value = ?, result_date = NOW()", $category, $username, $value); if ($results) { return true; } else { return false; } }
/** * Check if user is authorized * * @access public * @static * @return boolean Returns TRUE if authorized and FALSE otherwise */ public static function is_authorized() { if (isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { $user = new User_Model(); if ($user->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) { return true; } else { return false; } } else { return false; } }
/** * Change user profile * @param array post data * @param string user id */ public function change_data($post, $email) { $user = new User_Model(); $id = $user->get_id($email); if (self::profile_exists($email)) { //update data $data = array('customer_street' => $post['customer_street'], 'customer_city' => $post['customer_city'], 'customer_postal_code' => $post['customer_postal_code'], 'customer_phone' => $post['customer_phone'], 'billing_name' => $post['billing_name'], 'billing_street' => $post['billing_street'], 'billing_city' => $post['billing_city'], 'billing_postal_code' => $post['billing_postal_code'], 'billing_identity_number' => $post['billing_identity_number'], 'billing_vat_number' => $post['billing_vat_number']); $this->db->update(self::TN_EXTEND, $data, array('user' => $id)); } else { //create data $data['user'] = $id; $this->db->insert(self::TN_EXTEND, $data); } }
function login($userName, $password) { $this->db->select('*'); $this->db->from($this->table_name); $this->db->where(array('users.userName' => $userName)); $this->db->join('persons', 'persons.personId = users.personId'); $data = $this->db->get()->row(); $user = new User_Model($data); if (password_verify($password, $user->getPassword())) { return $user; } else { return false; } }
public function up() { /* remove trades table and set the trade column for shifts for pending trades */ if (!$this->db->field_exists('has_trade', 'shifts')) { $this->dbforge->add_column('shifts', array('has_trade' => array('type' => 'TINYINT', 'null' => FALSE, 'default' => 0))); } if ($this->db->table_exists('trades')) { // TRADE_MODEL:STATUS_PENDING - set the trade column $this->db->where('status', 1); $this->db->select('shift_id'); $query = $this->db->get('trades'); foreach ($query->result_array() as $row) { $sm = new Shift_Model(); $sm->get_by_id($row['shift_id']); $sm->has_trade = 1; $sm->save(); } // TRADE_MODEL:STATUS_APPROVED - remove current user $this->db->where('status', 2); $this->db->select('shift_id'); $query = $this->db->get('trades'); foreach ($query->result_array() as $row) { $sm = new Shift_Model(); $sm->get_by_id($row['shift_id']); $sm->user->get(); $sm->delete($sm->user, 'user'); $sm->save(); } // TRADE_MODEL:STATUS_ACCEPTED - switch the shift to the new user $this->db->where('status', 3); $this->db->select(array('shift_id', 'to_user_id')); $query = $this->db->get('trades'); foreach ($query->result_array() as $row) { $sm = new Shift_Model(); $sm->get_by_id($row['shift_id']); $um = new User_Model(); $um->get_by_id($row['to_user_id']); $sm->save(array('user' => $um)); } // TRADE_MODEL:STATUS_DENIED - DO NOTHING // $this->db->where('status', 4); // TRADE_MODEL:STATUS_COMPLETED - DO NOTHING // $this->db->where('status', 5); } /* now delete the trades table */ if ($this->db->table_exists('trades')) { $this->dbforge->drop_table('trades'); } }
public function __construct() { session_start(); global $links_on_page; $links_on_page = 3; if (isset($_SESSION['uid'])) { global $logged_user; $logged_user = new User_Model(); $logged_user->get_user_by_id($_SESSION['uid']); } else { global $logged_user; $logged_user = 0; } $this->configure_mail_settings(); }
function changeUserData($data) { $data['user'] = $data['user']; $data['name'] = $data['name']; $data['lastname'] = $data['lastname']; $data['email'] = $data['email']; $usuario = new User_Model(); if (!$usuario->alreadyExist($data['user'])) { $usuario->update($userID, $data); $registration = 1; } else { $msgerror = "User already exist"; } return $msgerror; }
/** * Tests User_Model::custom_validate * * @test * @dataProvider provider_custom_validate */ public function test_custom_validate($valid, $invalid) { // set up mock, for prevent_superadmin_modification $auth = $this->getMock('Auth', array('logged_in')); $auth->expects($this->exactly(2))->method('logged_in')->with($this->equalTo('superadmin'))->will($this->returnValue(True)); // Save initial data $initial_valid = $valid; $initial_invalid = $invalid; // Test with valid data $response = User_Model::custom_validate($valid, $auth); $this->assertEquals(TRUE, $valid instanceof Validation); $this->assertTrue($response, Kohana::debug($valid->errors())); // Test with invalid data $response = User_Model::custom_validate($invalid, $auth); $this->assertEquals(TRUE, $invalid instanceof Validation); $this->assertFalse($response); // restore valid, invalid $valid = $initial_valid; $invalid = $initial_invalid; // Test modification to superadmin as admin $auth = $this->getMock('Auth', array('logged_in')); $auth->expects($this->once())->method('logged_in')->with($this->equalTo('superadmin'))->will($this->returnValue(False)); $response = User_Model::custom_validate($valid, $auth); $this->assertTrue($valid instanceof Validation); $this->assertFalse($response, Kohana::debug($valid->errors())); }
/** * Load data of an user into the $auth_data static var * * @param string $username User name * @return boolean True on success, false on failure */ public function loadUser($username) { $users = DB::select(' SELECT u.*, s.firstname, s.lastname, s.student_number, s.promo FROM users u LEFT JOIN students s ON s.username = u.username WHERE u.username = ? ', array($username)); if (isset($users[0])) { User_Model::$auth_data = $users[0]; } else { throw new Exception('User not found'); } //permet de checker l'autenticit� de l'admin if (isset(User_Model::$auth_data['admin']) && User_Model::$auth_data['admin'] == 1) { if (Cache::read('auth_admin')) { Cache::delete('auth_admin'); } Cache::write('auth_admin', 1, 3600); } // If the user is a student if (isset(User_Model::$auth_data['student_number'])) { // Avatar User_Model::$auth_data['avatar_url'] = Student_Model::getAvatarURL(User_Model::$auth_data['student_number'], true); User_Model::$auth_data['avatar_big_url'] = Student_Model::getAvatarURL(User_Model::$auth_data['student_number'], false); } }
public function edit($id) { $user = User_Model::current(); $project = ORM::factory('project', $id); if (!$user->loaded && $project->user_can($user, 'edit')) { return $this->template->content = 'oh, come on!'; } if ($post = $this->input->post('project')) { $validation = Projects_utils::projects_edit_validation($post); if (!$project->validate($validation, true)) { return $this->template->content = Kohana::debug($validation->errors()); } if ($additional_user_emails = $this->input->post('additional_user_emails')) { $additional_user_roles = $this->input->post('additional_user_roles'); foreach ($additional_user_emails as $email) { Profiles_utils::reserve_email_if_available($email); } $additional_users = array_combine($additional_user_emails, $additional_user_roles); $project->add_user_roles($additional_users); } url::redirect($project->local_url); } else { HTMLPage::add_style('forms'); $this->template->content = View::factory('projects/edit')->bind('project_types', Projects_utils::get_project_types_dropdown_array())->bind('project', $project)->bind('user', $user); } }
/** * 单例模式 * @return User_Model */ public static function &instance() { if (!isset(self::$instance)) { // Create a new instance self::$instance = new User_Model(); } return self::$instance; }
/** * This method will handle the login process */ function login() { $this->load->model('User_Model'); $user_model = new User_Model(); $json_data = json_decode(file_get_contents('php://input')); $email = $json_data->{'email'}; $password = $json_data->{'password'}; $user_details = $user_model->getUserDetials($email, $password); if ($user_details != NULL) { $user_details[0]["error"] = false; $this->session->set_userdata('user', $user_details); echo json_encode($user_details[0]); } else { $data = array("error" => true, "message" => "invalid username or password"); echo json_encode($data); } }
public function resetPassword() { $post = $this->input->post(); $resetP = User_Model::changePasswordStatic($post); if ($resetP) { $data = array('message_display' => 'Password successfully reset'); $this->load->view('login/login_form', $data); } }
public function archiveList() { $resultList = $this->delete->getArchivedFiles(); $data = array('fileList' => json_decode($resultList), 'allUsers' => User_Model::getAllUsers(), 'trashCanTitle' => 'Permanently Delete File', 'authorizeButtonTitle' => 'Undelete This File, will send file back for approval'); $this->load->view('templates/header', array('pageTitle' => 'Archived Files')); $this->load->view('home_view', $data); $this->load->view('file/delete_view'); $this->load->view('templates/footer'); }
function index($user_id = 0) { /* load */ $this->{$this->model}->include_related('user', 'email')->include_related('user', 'first_name')->include_related('user', 'last_name'); if ($user_id) { $this->{$this->model}->where_related('user', 'id', $user_id); $user = new User_Model(); $user->get_by_id($user_id); $this->data['object'] = $user; } $this->data['user_id'] = $user_id; $this->data['entries'] = $this->{$this->model}->get()->all; if ($user_id) { $this->inherit_views('admin/users/edit'); } $this->set_include('loginlog'); $this->load->view($this->template, $this->data); }
/** * Sauvegarder le nouvel mot de passe d'un user * * @return void */ public function update_username() { $username = $this->input->post('username'); if (!User_Model::verification_username($username)) { $this->user->update(array('username' => $username)); echo $username; } else { echo $this->user->username; } }