/** * {@inheritdoc} */ public function handle(ServerRequestInterface $request) { $body = $request->getParsedBody(); $email = array_get($body, 'email'); $username = array_get($body, 'username'); $password = array_get($body, 'password'); $user = User::register($username, $email, $password); $user->activate(); if (isset($token)) { foreach ($token->payload as $k => $v) { $user->{$k} = $v; } } $user->create_from = '来自社区账号系统'; $user->save(); return new JsonResponse(['userId' => $user->id]); }
/** * {@inheritdoc} */ public function handle(ServerRequestInterface $request) { $body = $request->getParsedBody(); $identification = array_get($body, 'identification'); $password = array_get($body, 'password'); $lifetime = array_get($body, 'lifetime', 3600); $data = 'email=' . $identification . '&password='******'https://dashboard.pingxx.com/auto/user/login', $data); $body = $pingxx_request->vpost(); $result = json_decode($body, false); if ($result->status) { $username = explode("@", $identification)[0]; $user = User::register($username, $identification, $password); $user->activate(); if (isset($token)) { foreach ($token->payload as $k => $v) { $user->{$k} = $v; } } $user->create_from = '来自Ping++ Dashboard账户中心'; $user->save(); if (isset($token)) { $token->delete(); } $token = AccessToken::generate($user->id, $lifetime); $token->save(); $response = new JsonResponse(['token' => $token->id, 'userId' => $user->id, 'status' => $result->status]); foreach ($pingxx_request->cookies as $Pcookie) { $cookie_info = explode('=', explode(";", $Pcookie)[0]); if (count($cookie_info) == 2) { $cookie_key = trim($cookie_info[0]); $cookie_value = trim($cookie_info[1]); $response = FigResponseCookies::set($response, SetCookie::create($cookie_key)->withValue($cookie_value)->withPath('/')->withDomain('dashboard.pingxx.com')); } } return $response; } else { throw new PermissionDeniedException($result->data->message); } }
/** * @param RegisterUser $command * @throws PermissionDeniedException if signup is closed and the actor is * not an administrator. * @throws \Flarum\Core\Exception\InvalidConfirmationTokenException if an * email confirmation token is provided but is invalid. * @return User */ public function handle(RegisterUser $command) { $actor = $command->actor; $data = $command->data; if (!$this->settings->get('allow_sign_up')) { $this->assertAdmin($actor); } $username = array_get($data, 'attributes.username'); $email = array_get($data, 'attributes.email'); $password = array_get($data, 'attributes.password'); // If a valid authentication token was provided as an attribute, // then we won't require the user to choose a password. if (isset($data['attributes']['token'])) { $token = AuthToken::validOrFail($data['attributes']['token']); $password = $password ?: str_random(20); } $user = User::register($username, $email, $password); // If a valid authentication token was provided, then we will assign // the attributes associated with it to the user's account. If this // includes an email address, then we will activate the user's account // from the get-go. if (isset($token)) { foreach ($token->payload as $k => $v) { $user->{$k} = $v; } if (isset($token->payload['email'])) { $user->activate(); } } $this->events->fire(new UserWillBeSaved($user, $actor, $data)); $this->validator->assertValid(array_merge($user->getAttributes(), compact('password'))); $user->save(); if (isset($token)) { $token->delete(); } $this->dispatchEventsFor($user, $actor); return $user; }
protected function createAdminUser() { $admin = $this->adminUser; if ($admin['password'] !== $admin['password_confirmation']) { throw new Exception('The password did not match its confirmation.'); } $this->info('Creating admin user ' . $admin['username']); $user = User::register($admin['username'], $admin['email'], $admin['password']); $user->is_activated = 1; $user->save(); $user->groups()->sync([Group::ADMINISTRATOR_ID]); }
public static function ensureUser($userInfo, $events, $actor) { // Get the user that has this ID if it already exists. $user = User::where(['singleso_id' => $userInfo['id']])->first(); // Change any dupes to keep the unique table column integrity. foreach (static::$userUnique as $k => $v) { // If user is new or property is different, then check for dupe. if (!$user || $user->{$k} !== $userInfo[$v[0]]) { // Check for user with dupe property. $dupe = User::where([$k => $userInfo[$v[0]]])->first(); // If conflict, rename to unique until next login. if ($dupe) { // If the account is local only, throw exception. if (!isset($dupe->singleso_id)) { throw new SingleSOException([sprintf('Local account "%s" conflict.', $k)]); } $dupe->{$k} = sprintf($v[1], $dupe->id); $dupe->save(); } } } // If user exists, check for changes, and save if different. if ($user) { $changed = false; foreach (static::$userUnique as $k => $v) { if ($user->{$k} !== $userInfo[$v[0]]) { $user->{$k} = $userInfo[$v[0]]; $changed = true; } } if ($changed) { $user->save(); } } else { $user = User::register($userInfo['username'], $userInfo['email'], ''); // Add the unique ID and activate. $user->singleso_id = $userInfo['id']; $user->activate(); // Set an internal flag, trigger event, and remove the flag. $user->_singleso_registered_user = true; $events->fire(new UserWillBeSaved($user, $actor, ['attributes' => ['username' => $userInfo['username'], 'email' => $userInfo['email'], 'password' => '']])); unset($user->_singleso_registered_user); // Save to the database. $user->save(); } return $user; }