/** * Create a new service user from raw data. * * @param string $email * @param string $password * @param string $UDID * * @return integer | string User id or error message. */ public function addNewServiceUser($email, $password, $UDID) { $dbTable = $this->getUpdateTable(); // Check email existence. $row = $this->getRow(array(array('where' => 'email = ?', 'bind' => $email))); if ($row) { return self::ADD_USER_ERROR_EMAIL_EXISTS; } // Add $userRowData = array('email' => $email, 'password' => Auth_Wrapper_User::getPasswordHash($password), 'UDID' => $UDID, 'user_type' => self::SERVICE_USER_TYPE, 'created_datetime' => date('Y-m-d H:i:s')); $newRow = $dbTable->createRow($userRowData); try { $newRow->save(); } catch (Exception $e) { return 'Creating error: ' . $e->getMessage(); } return $newRow->id; }
/** * Update the user with the form data. * * @param Object_User $user * @return boolean */ public function updateUser($user) { if (!is_a($user, 'Object_User')) { return false; } // Check email duplication if (Repo_User::getInstance()->emailExists($this->getValue('email'), $user->id)) { $this->getElement('email')->addError('Email exists: ' . $this->getValue('email')); return false; } else { $user->email = $this->getValue('email'); } $newPassword = $this->getValue('password'); if (!empty($newPassword)) { $user->password = Auth_Wrapper_User::getPasswordHash($this->getValue('password')); } $roleIds = $this->getValue('role'); $user->firstname = $this->getValue('firstname'); $user->surname = $this->getValue('surname'); $user->UDID = $this->getValue('UDID'); if (is_array($roleIds)) { $roleIds = implode(',', $roleIds); } $user->role_id = $roleIds; $user->client_id = $this->getValue('client'); return $user->save(); }
/** * Change password by providing the current password. * * @param string $old * @param string $new * @return mixed */ public function changePassword($old, $new) { if (Auth_Wrapper_User::verifyAuth($this->email, $old) === false) { return 'Invalid current password provided'; } $this->password = Auth_Wrapper_User::getPasswordHash($new); $this->save(); return true; }