/** * Register new user */ public static function register($username, $password, $email, $display_name) { $salt = User::make_salt(); $hashed_pass = crypt($password . $salt); $attributes = array('username' => $username, 'password' => $hashed_pass, 'salt' => $salt, 'email' => $email, 'display_name' => $display_name); $new_user = new User($attributes); $new_user->save(); $attributes = array('user_id' => $new_user->id, 'meta_name' => 'user_level', 'meta_value' => 1); $new_meta = new Usermeta($attributes); $new_meta->save(); }
/** * 创建用户元数据 * * @param integer $uid 用户ID * @param string $metaKey 键名 * @param string $metaValue 值 * @throws ResourceException */ public function postUserMetaAction($uid, $metaKey, $metaValue) { $meta = new Usermeta(); $meta->UID = $uid; $meta->meta_key = $metaKey; $meta->meta_value = $metaValue; //使用元数据过滤器处理特定的键值 $metaFilter = new UserMetaFilterController(); $metaFilter->run($uid, $metaKey, $metaValue); if ($meta->create()) { $this->response(201, 'Created'); $this->response->setHeader('Location', 'user_meta/' . $meta->meta_id); } else { throw new ResourceException('Internal Server Error', 500); } }
public function index() { if ($_POST) { $username = $this->input->post('login_username'); $password = $this->input->post('login_pass'); $valid_login = User::validate_login($username, $password); if ($valid_login) { $this_user = User::find_by_username($username); $user_level = Usermeta::get_user_level($this_user->id); $session_data = array('user_id' => $this_user->id, 'username' => $this_user->username, 'password' => $this_user->password, 'email' => $this_user->email, 'display_name' => $this_user->display_name, 'user_level' => $user_level, 'chat_color' => get_chat_color(intval($user_level)), 'redirect' => $this->session->userdata('redirect')); $this->session->set_userdata($session_data); redirect($this->session->userdata('redirect')); } else { $this->content_view = 'login_error'; } } else { redirect('home'); } }
public static function get_user_level($userid) { $meta = Usermeta::find(array('select' => 'meta_value', 'conditions' => array('user_id = ? AND meta_name="user_level"', $userid))); return intval($meta->meta_value); }
} catch (Exception $e) { } redirect_to(App::url('oauth.php')); } $user = Session::get('oauth_user'); if (empty($user)) { redirect_to(App::url()); } $provider = $user['provider']; $userId = Usermeta::newQuery()->where('meta_key', "{$provider}_id")->where('meta_value', $user['id'])->pluck('user_id'); if (Auth::check()) { if (is_null($userId)) { Usermeta::add(Auth::user()->id, "{$provider}_id", $user['id'], true); Usermeta::add(Auth::user()->id, "{$provider}_avatar", $user['avatar'], true); if (!empty($user['profile'])) { Usermeta::add(Auth::user()->id, "{$provider}_profile", $user['profile'], true); } } redirect_to($settingsPage); } if (is_null($userId)) { $data = array('email' => $user['email'], 'username' => $user['username'], 'usermeta' => array("{$provider}_id" => $user['id'], 'avatar_type' => $provider, "{$provider}_avatar" => $user['avatar'])); if (empty($data['username'])) { $data['username'] = sprintf('%s%s', $user['first_name'], $user['last_name']); } if (!empty($user['profile'])) { $data['usermeta']["{$provider}_profile"] = $user['profile']; } if (array_key_exists($user['locale'], Config::get('app.locales'))) { $data['usermeta']['locale'] = $user['locale']; }
public function __construct(&$xpdo) { parent::__construct($xpdo); }
} ?> </ul> <?php break; // Delete account // Delete account case 'delete': if (!Config::get('auth.delete_account')) { redirect_to('?p=account'); } if (isset($_POST['submit']) && csrf_filter()) { $id = Auth::user()->id; User::where('id', $id)->limit(1)->delete(); Usermeta::delete($id); Message::newQuery()->where('to_user', $id)->orWhere('from_user', $id)->delete(); Contact::deleteAll($id); Comments::deleteUserComments($id); Auth::logout(); redirect_to(App::url()); } ?> <h3 class="page-header"><?php echo _e('main.delete_account'); ?> </h3> <?php _e('main.delete_account_message'); ?> <form action="" method="POST">
function ajax_delete_users() { if (!Auth::userCan('delete_users')) { json_message(trans('errors.permission'), false); } $users = isset($_POST['users']) ? $_POST['users'] : array(); parse_str($users, $data); if (isset($data['users'])) { $users = array(); foreach ((array) $data['users'] as $key => $id) { if (is_numeric($id) && (int) $id != Auth::user()->id) { $users[] = $id; } } if (count($users)) { $values = array_values($users); User::whereIn('id', $values)->limit(count($users))->delete(); Usermeta::newQuery()->whereIn('user_id', $values)->delete(); Message::newQuery()->whereIn('to_user', $values)->orWhereIn('from_user', $values)->delete(); Contact::newQuery()->whereIn('user1', $values)->orWhereIn('user2', $values)->delete(); Comments::deleteUserComments($values); } } json_message(); }