Beispiel #1
0
 /**
  * Add new user using data provided by administrator from admin panel.
  * @param $postData All data filled in administrator's "Add User" form
  * @return array Result that contain status (error or success) and message.
  */
 public function add($postData)
 {
     // prepare required objects and arrays
     $result = array();
     $reg = new ASRegister();
     $errors = $reg->validateUser($postData, false);
     // if count ( $errors ) > 0 means that validation didn't passed and that there are errors
     if (count($errors) > 0) {
         $result = array("status" => "error", "errors" => $errors);
     } else {
         //validation passed
         $data = $postData['userData'];
         // insert user login info
         $this->db->insert('as_users', array('email' => $data['email'], 'username' => $data['username'], 'password' => $reg->hashPassword($data['password']), 'confirmed' => 'Y', 'register_date' => date('Y-m-d H:i:s')));
         // get user id
         $id = $this->db->lastInsertId();
         // insert users details
         $this->db->insert('as_user_details', array('user_id' => $id, 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'phone' => $data['phone'], 'address' => $data['address']));
         // generate response
         $result = array("status" => "success", "msg" => ASLang::get("user_added_successfully"));
     }
     return $result;
 }