function reset_password($code) { $password = $this->input->post('password'); $status = $this->check_code($code); if ($status == TRUE) { if ($this->form_validation->required($password) == FALSE) { $this->session->set_flashdata('message', array('Please enter your new password.')); redirect('/reset/' . $code); } elseif ($this->form_validation->min_length($password, 6) == FALSE) { $this->session->set_flashdata('message', array('Password should be 6 characters or more.')); redirect('/reset/' . $code); } else { $query = $this->db->query("SELECT username FROM user WHERE forget_password='******' LIMIT 1"); $data = array('password' => md5($password), 'forget_password' => ''); manipulate_database('update', 'user', $data, array('forget_password' => $code)); $this->session->set_flashdata('message', array('All set!')); return $query->row()->username; } } else { redirect('/reset'); } }
function disconnect_twitter($username, $type = TRUE) { $data = array('access_token' => '', 'access_token_secret' => '', 'twitter' => '', 'twitter_id' => ''); manipulate_database('update', 'user', $data, array('username' => $username)); $this->session->set_flashdata('message', array('Success! You can reconnect by clicking the image below.')); redirect('/settings/twitter'); }
function edit_form_submit($quizid, $title, $change) { $row = $this->db->query("SELECT title FROM quiz WHERE id='{$quizid}' LIMIT 1")->row(); $data = array('title' => make_it_safe($title)); manipulate_database('update', 'quiz', $data, array('id' => $quizid)); if ($row->title != $title) { $change = TRUE; } if ($change == TRUE) { $data = array('last_edit_time' => time()); manipulate_database('update', 'quiz', $data, array('id' => $quizid)); } }
function show_results($userid, $badgeid, $result, $array) { if ($result == TRUE) { $row = $this->db->query("SELECT id, point, name FROM badge WHERE id='{$badgeid}' LIMIT 1")->row(); $num_rows = $this->db->query("SELECT COUNT(id) AS total FROM badges WHERE user_id='{$userid}' AND badge_id='{$badgeid}' LIMIT 1")->row()->total; if ($num_rows == 0) { $data = array('user_id' => $userid, 'badge_id' => $row->id, 'point' => $row->point, 'time' => time()); manipulate_database('insert', 'badges', $data); $CI =& get_instance(); $CI->load->model('twitter_model'); $CI->twitter_model->auto_share($userid, FALSE, $badgeid, $row->name); array_push($array, 'You just unlocked the badge "<a href="/badges/' . $row->id . '">' . $row->name . '</a>"!'); } } return $array; }
function insert_tags($quizid, $tag) { $data = array('quiz_id' => $quizid, 'tag' => strtolower(make_it_safe($tag))); manipulate_database('insert', 'tag', $data); }
function follow() { $following = get_username(); $follower = $this->input->post('follower'); if ($follower == '' || $this->input->post('hell_yeah') != 52012) { stupid(); } $page = $this->input->post('page'); $query = $this->db->query("SELECT id FROM follow WHERE following_user_id='{$following}' AND follower_user_id='{$follower}' AND deleted_time='' LIMIT 1"); if ($query->num_rows() == 1) { $data = array('deleted_time' => mktime()); manipulate_database('update', 'follow', $data, array('following_user_id' => $following, 'follower_user_id' => $follower, 'deleted_time' => '')); $return = '+ Follow'; } else { $data = array('following_user_id' => $following, 'follower_user_id' => $follower, 'time' => mktime()); manipulate_database('insert', 'follow', $data); $return = '- Unfollow'; } if ($page == $following) { $followingquery = $this->db->query("SELECT COUNT(id) AS total FROM follow WHERE following_user_id='{$following}' AND deleted_time=''"); $followerquery = $this->db->query("SELECT COUNT(id) AS total FROM follow WHERE follower_user_id='{$following}' AND deleted_time=''"); } else { $followerquery = $this->db->query("SELECT COUNT(id) AS total FROM follow WHERE follower_user_id='{$follower}' AND deleted_time=''"); $followingquery = $this->db->query("SELECT COUNT(id) AS total FROM follow WHERE following_user_id='{$follower}' AND deleted_time=''"); } if ($page == $following || $page == $follower) { $followernumber = $followerquery->row()->total; $followingnumber = $followingquery->row()->total; $type = 1; } else { $followernumber = 0; $followingnumber = 0; $type = 0; } $badge = $this->badge_model->check($following, 'follow'); $data = array('result' => $return, 'type' => $type, 'followernumber' => $followernumber, 'followingnumber' => $followingnumber); echo json_encode($data); }
function login($username) { $username = $this->db->query("SELECT username FROM user WHERE username='******' LIMIT 1")->row()->username; $this->session->set_userdata('nihaoma', $username); $cookie = array('name' => 'nihaoma', 'value' => $username, 'expire' => '1200000', 'domain' => '.' . str_replace('http://', '', rtrim(base_url(), '/')), 'path' => '/', 'prefix' => 'ole_'); set_cookie($cookie); $data = array('last_login_time' => time(), 'forget_password' => ''); manipulate_database('update', 'user', $data, array('username' => $username)); }