1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\Modules\StandardRegisterFormWebclient;
9:
10: /**
11: * Displays standard register form with ability to specify user name, account login and password.
12: *
13: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
14: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
15: * @copyright Copyright (c) 2019, Afterlogic Corp.
16: *
17: * @package Modules
18: */
19: class Module extends \Aurora\System\Module\AbstractWebclientModule
20: {
21: /***** public functions might be called with web API *****/
22: /**
23: * Obtains list of module settings for authenticated user.
24: *
25: * @return array
26: */
27: public function GetSettings()
28: {
29: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
30:
31: return array(
32: 'ServerModuleName' => $this->getConfig('ServerModuleName', 'StandardRegisterFormWebclient'),
33: 'HashModuleName' => $this->getConfig('HashModuleName', 'login'),
34: 'CustomLogoUrl' => $this->getConfig('CustomLogoUrl', ''),
35: 'InfoText' => $this->getConfig('InfoText', ''),
36: 'BottomInfoHtmlText' => $this->getConfig('BottomInfoHtmlText', ''),
37: );
38: }
39:
40: /**
41: * Broadcasts Register event to other modules to log in the system with specified parameters.
42: *
43: * @param string $Name New name for user.
44: * @param string $Login Login for authentication.
45: * @param string $Password Password for authentication.
46: * @param int $UserId Identifier of user which will contain new account.
47: * @return array
48: * @throws \Aurora\System\Exceptions\ApiException
49: */
50: public function Register($Login, $Password, $UserId)
51: {
52: \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::Anonymous);
53:
54: if (\Aurora\System\Api::getAuthenticatedUserId()) {
55: return false;
56: }
57:
58: if (empty($UserId))
59: {
60: $bPrevState = \Aurora\System\Api::skipCheckUserRole(true);
61:
62: $UserId = \Aurora\Modules\Core\Module::Decorator()->CreateUser(0, $Login);
63:
64: \Aurora\System\Api::skipCheckUserRole($bPrevState);
65: }
66:
67: if (empty($UserId))
68: {
69: throw new \Aurora\System\Exceptions\ApiException(\Aurora\System\Notifications::InvalidInputParameter);
70: }
71:
72: $mResult = false;
73:
74: $refArgs = array (
75: 'Login' => $Login,
76: 'Password' => $Password,
77: 'UserId' => $UserId,
78: );
79: $this->broadcastEvent(
80: 'Register',
81: $refArgs,
82: $mResult
83: );
84:
85: if (!empty($mResult))
86: {
87: $oLoginDecorator = \Aurora\Modules\StandardLoginFormWebclient\Module::Decorator();
88: $mResult = $oLoginDecorator->Login($Login, $Password);
89: if ($mResult && isset($mResult['AuthToken'])) {
90: \Aurora\System\Api::getAuthenticatedUserId($mResult['AuthToken']);
91: }
92: }
93:
94: return $mResult;
95: }
96: /***** public functions might be called with web API *****/
97: }
98: