Pagekit\User\Controller\RegistrationController::registerAction PHP Method

registerAction() public method

public registerAction ( $data )
    public function registerAction($data)
    {
        try {
            if (App::user()->isAuthenticated() || $this->module->config('registration') == 'admin') {
                return App::redirect();
            }
            if (!App::csrf()->validate()) {
                throw new Exception(__('Invalid token. Please try again.'));
            }
            $password = @$data['password'];
            if (trim($password) != $password || strlen($password) < 6) {
                throw new Exception(__('Password must be 6 characters or longer.'));
            }
            $user = User::create(['registered' => new \DateTime(), 'name' => @$data['name'], 'username' => @$data['username'], 'email' => @$data['email'], 'password' => App::get('auth.password')->hash($password), 'status' => User::STATUS_BLOCKED]);
            $token = App::get('auth.random')->generateString(32);
            $admin = $this->module->config('registration') == 'approval';
            if ($verify = $this->module->config('require_verification') or $admin) {
                $user->activation = $token;
            } else {
                $user->status = User::STATUS_ACTIVE;
            }
            $user->validate();
            $user->save();
            if ($verify) {
                $this->sendVerificationMail($user);
                $message = __('Complete your registration by clicking the link provided in the mail that has been sent to you.');
            } elseif ($admin) {
                $this->sendApproveMail($user);
                $message = __('Your user account has been created and is pending approval by the site administrator.');
            } else {
                $this->sendWelcomeEmail($user);
                $message = __('Your user account has been created.');
            }
        } catch (Exception $e) {
            App::abort(400, $e->getMessage());
        }
        App::message()->success($message);
        return ['redirect' => App::url('@user/login')];
    }