PHP User::from_array Examples

PHP User::from_array - 13 examples found. These are the top rated real world PHP examples of User::from_array extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 function index()
 {
     $user = $this->login_manager->get_user();
     if ($user !== FALSE) {
         // already logged in, redirect to welcome page
         redirect('welcome');
     }
     // Create a user to store the login validation
     $user = new User();
     if ($this->input->post('username') !== FALSE) {
         // A login was attempted, load the user data
         $user->from_array($_POST, array('username', 'password'));
         // get the result of the login request
         $login_redirect = $this->login_manager->process_login($user);
         if ($login_redirect) {
             if ($login_redirect === TRUE) {
                 // if the result was simply TRUE, redirect to the welcome page.
                 redirect('welcome');
             } else {
                 // otherwise, redirect to the stored page that was last accessed.
                 redirect($login_redirect);
             }
         }
     }
     $user->load_extension('htmlform');
     $this->output->enable_profiler(TRUE);
     $this->load->view('template_header', array('title' => 'Login', 'hide_nav' => TRUE));
     $this->load->view('login', array('user' => $user));
     $this->load->view('template_footer');
 }
Example #2
0
 function signup()
 {
     $u = new User();
     $fields_render = array('full_name', 'uni', 'year', 'major', 'password', 'confirm', 'pwhash', 'scholar', 'server_salt' => array('value' => $this->config->item('server_salt')));
     $data['title'] = 'Sign up';
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $u->from_array($_POST, $fields_render);
         // Special case password handling.
         if ($this->input->post('pwhash')) {
             $u->password = $this->input->post('pwhash');
         } else {
             if ($this->input->post('password')) {
                 $u->password = User::hash($this->input->post('password'));
                 // Also has the confirm field
                 $u->confirm = User::hash($this->input->post('confirm'));
                 $this->session->set_flashdata('msg', "Your password was sent in cleartext because you did not enable Javascript. Please enable Javascript for security.");
             }
         }
         if ($u->save()) {
             //validation rules run
             $this->_signup_success();
         } else {
             $data['error'] = $u->error->string;
         }
     }
     // Otherwise, or if error, render a form
     $data['form'] = $u->render_form($fields_render);
     $this->load->view("form_password.php", $data);
 }
Example #3
0
 function signup()
 {
     if ($_POST) {
         if (@$_POST['level_id'] == 4 && @$_POST['code'] == "6880" || @$_POST['level_id'] == 5 || @$_POST['level_id'] == 7) {
             $user = new User();
             $user->from_array($_POST);
             $user->last_login = date('Y-m-d H:i:s');
             if (isset($_POST['newsletters'])) {
                 $user->newsletter = implode(',', $_POST['newsletters']);
             }
             $user->save();
             $_POST['user_id'] = $user->id;
             $_POST['birth_day'] = Date2DB($_POST['birth_day']);
             $_POST['permission_id'] = 4;
             $user->profile->from_array($_POST);
             $user->profile->save();
             login($_POST['username'], $_POST['password']);
         } else {
             if (@$_POST['level_id'] == 4 && @$_POST['code'] != "6880") {
                 set_notify('error', 'รหัสเจ้าหน้าที่ไม่ถูกต้อง');
             }
         }
         redirect('home');
     }
 }
Example #4
0
 public function save()
 {
     if ($_POST) {
         $user = new User(user('id'));
         $user->from_array($_POST);
         $user->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('users/admin/profiles');
 }
Example #5
0
 public function save($id = NULL)
 {
     if ($_POST) {
         $user = new User($id);
         // $_POST['password'] = md5(sha1($_POST['password']."secret"));
         $user->from_array($_POST);
         $user->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('users/admin/users');
 }
Example #6
0
 function save($id)
 {
     if ($_POST) {
         $user = new User($id);
         $user->from_array($_POST);
         $user->save();
         $user->profile->from_array($_POST);
         $user->profile->user_id = $user->id;
         $user->profile->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('officer');
 }
Example #7
0
 function edit($id = FALSE)
 {
     $this->data['u'] = $u = new User($id);
     if ($_POST) {
         $u->from_array($this->input->post(), array('username', 'email', 'admin'));
         if ($u->save()) {
             $this->session->set_flashdata('msg', '<div class="alert alert-success">User was edited succesfully</div>');
             redirect('users/index');
         } else {
             $this->data['errors'] = $u->error->all;
         }
     }
 }
Example #8
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $user = new User($id);
         $user->from_array($_POST);
         $user->save();
         $_POST['birth_day'] = Date2DB($_POST['birth_day']);
         $user->profile->from_array($_POST);
         $user->profile->user_id = $user->id;
         $user->profile->save();
         set_notify('success', 'บันทึกข้อมูลเรียบร้อยแล้วค่ะ');
         redirect($_POST['referer']);
     }
 }
Example #9
0
 function save()
 {
     if ($_POST) {
         $user = new User($this->session->userdata('id'));
         $user->from_array($_POST);
         $user->save();
         $_POST['user_id'] = $user->id;
         if ($_FILES['image']['name']) {
             $user->profile->delete_file($user->profile->id, 'uploads/users/', 'avatar');
             $_POST['avatar'] = $user->profile->upload($_FILES['image'], 'uploads/users/', 140, 140);
             $user->profile->thumb('uploads/users/thumbs/', 100, 100);
             $user->profile->thumb('uploads/users/thumbs50x50/', 50, 50);
         }
         $_POST['birth_day'] = Date2DB($_POST['birth_day']);
         $user->profile->from_array($_POST);
         $user->profile->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('users/admin/profiles');
 }
Example #10
0
 function account_setting_save()
 {
     if ($_POST) {
         $user = new User();
         $_POST['id'] = $this->session->userdata('id');
         $_POST['signature'] = $_POST['detail'];
         $user->from_array($_POST);
         $user->save();
         set_notify('success', 'บันทึกข้อมูลเรียบร้อย');
     }
     redirect($_SERVER['HTTP_REFERER']);
 }
Example #11
0
 public function my_profile_save()
 {
     if ($_POST) {
         $rs = new User();
         // ถ้ามีการอัพโหลดรูป
         // if($_FILES['upload']['tmp_name'] != ""){
         // $image = file_get_contents($_FILES['upload']['tmp_name']);
         // $client_id="94af93212e2e617";//Your Client ID here
         // $ch = curl_init();
         // curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
         // curl_setopt($ch, CURLOPT_POST, TRUE);
         // curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         // curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Authorization: Client-ID ' . $client_id ));
         // curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'image' => base64_encode($image) ));
         // $reply = curl_exec($ch);
         // curl_close($ch);
         // $reply = json_decode($reply);
         // $_POST['image'] = @$reply->data->link;
         // }
         if ($_POST['image'] != "") {
             $_POST['image'] = strip_tags($_POST['image']);
         }
         $_POST['display_name'] = strip_tags($_POST['display_name']);
         $_POST['detail'] = strip_tags($_POST['detail']);
         if ($_POST['social_line'] != "") {
             $_POST['social_line'] = strip_tags($_POST['social_line']);
         }
         if ($_POST['social_instagram'] != "") {
             $_POST['social_instagram'] = strip_tags($_POST['social_instagram']);
         }
         if ($_POST['social_twitter'] != "") {
             $_POST['social_twitter'] = strip_tags($_POST['social_twitter']);
         }
         if ($_POST['social_facebook'] != "") {
             $_POST['social_facebook'] = strip_tags($_POST['social_facebook']);
         }
         $rs->from_array($_POST);
         $rs->save();
         set_notify('success', 'บันทึกข้อมูลเรียบร้อย');
     }
     redirect('home/my_profile');
 }
Example #12
0
 function index()
 {
     list($params, $id) = $this->parse_params(func_get_args());
     // Create or update
     if ($this->method === 'get') {
         if (!$this->auth) {
             $this->error('401', 'Not authorized to perform this action.');
             return;
         }
     } else {
         // TODO: Stress test permissions
         $u = new User();
         switch ($this->method) {
             case 'post':
             case 'put':
                 if ($this->method == 'put') {
                     // Updates can only be carried out by the user or an administrator
                     if ($this->auth_user_id != $id && $this->auth_role != 'god' && $this->auth_role != 'admin') {
                         $this->error('401', 'Not authorized to perform this action.');
                         return;
                     }
                     $u->get_by_id($id);
                     if (!$u->exists()) {
                         $this->error('404', "User with ID: {$id} not found.");
                         return;
                     }
                 } else {
                     if (is_null($id)) {
                         // Only admins can create users
                         if ($this->auth_role != 'god' && $this->auth_role != 'admin') {
                             $this->error('401', 'Not authorized to perform this action.');
                             return;
                         }
                     }
                 }
                 $u->from_array($_POST, array(), true);
                 $this->redirect("/users/{$u->id}");
                 break;
                 // case 'delete':
                 // 	if ($this->auth_role != 'god' && $this->auth_role != 'admin')
                 // 	{
                 // 		$this->error('401', 'Not authorized to perform this action.');
                 return;
                 // 	}
                 // 	if (is_null($id))
                 // 	{
                 // 		$this->error('403', 'Required parameter "id" not present.');
                 return;
                 // 	}
                 // 	else
                 // 	{
                 // 		// TODO
                 // 	}
                 // 	exit;
                 break;
         }
     }
     $u = new User();
     // No id, so we want a list
     if (is_null($id)) {
         $options = array('page' => 1, 'limit' => false);
         $options = array_merge($options, $params);
         if (!is_numeric($options['limit'])) {
             $options['limit'] = false;
         }
         $final = $u->paginate($options);
         $data = $u->get_iterated();
         if (!$options['limit']) {
             $final['per_page'] = $data->result_count();
             $final['total'] = $data->result_count();
         }
         $final['users'] = array();
         foreach ($data as $user) {
             $final['users'][] = $user->to_array($params);
         }
     } else {
         $user = $u->get_by_id($id);
         if ($u->exists()) {
             $final = $user->to_array($params);
         } else {
             $this->error('404', "User with ID: {$id} not found.");
             return;
         }
     }
     $this->set_response_data($final);
 }
Example #13
0
 /**
  * Allows the creation of an Administrator
  *
  */
 function init($save = FALSE)
 {
     $first_time = $this->session->userdata('first_time');
     if (!$first_time) {
         show_error('This page can only be accessed the first time.');
     }
     $user = new User();
     if ($save) {
         $user->trans_start();
         $user->from_array($_POST, array('name', 'email', 'username', 'password', 'confirm_password'));
         $group = new Group();
         $group->get_by_id(1);
         if ($user->save($group)) {
             $user->password = $this->input->post('password');
             if (!$this->login_manager->process_login($user)) {
                 show_error('Errors: <ul><li>' . implode('</li><li>', $user->error->all) . '</li></ul><pre>' . var_export($user->error, TRUE) . '</pre>');
             }
             $this->session->unset_userdata('first_time');
             $user->trans_complete();
             redirect('welcome');
         }
     }
     $user->load_extension('htmlform');
     // ID is not included because it is not necessary
     $form_fields = array('Contact Information' => 'section', 'name' => array('label' => 'Your Name'), 'email', 'Login Information' => 'section', 'username', 'password', 'confirm_password');
     $this->load->view('template_header', array('title' => 'Set Up Your Account', 'section' => 'admin'));
     $this->load->view('admin/init', array('user' => $user, 'form_fields' => $form_fields));
     $this->load->view('template_footer');
 }