Completed
Push — master ( 0d52ea...f30158 )
by Sherif
06:07
created
src/Modules/OauthClients/Resources/Lang/ar/errors.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your error messages.
7
-     */
5
+	/**
6
+	 * Here goes your error messages.
7
+	 */
8 8
 
9 9
 ];
Please login to merge, or discard this patch.
src/Modules/Roles/Resources/Lang/en/errors.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your error messages.
7
-     */
5
+	/**
6
+	 * Here goes your error messages.
7
+	 */
8 8
 
9 9
 ];
Please login to merge, or discard this patch.
src/Modules/Roles/Resources/Lang/ar/errors.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your error messages.
7
-     */
5
+	/**
6
+	 * Here goes your error messages.
7
+	 */
8 8
 
9 9
 ];
Please login to merge, or discard this patch.
src/Modules/Roles/ModelObservers/RoleObserver.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -7,69 +7,69 @@
 block discarded – undo
7 7
  */
8 8
 class RoleObserver
9 9
 {
10
-    public function saving($model)
11
-    {
12
-        //
13
-    }
10
+	public function saving($model)
11
+	{
12
+		//
13
+	}
14 14
 
15
-    public function saved($model)
16
-    {
17
-        //
18
-    }
15
+	public function saved($model)
16
+	{
17
+		//
18
+	}
19 19
 
20
-    public function creating($model)
21
-    {
22
-        //
23
-    }
20
+	public function creating($model)
21
+	{
22
+		//
23
+	}
24 24
 
25
-    public function created($model)
26
-    {
27
-        //
28
-    }
25
+	public function created($model)
26
+	{
27
+		//
28
+	}
29 29
 
30
-    /**
31
-     * Prevent updating of the admin role.
32
-     *
33
-     * @param  object $model the model beign updated.
34
-     * @return void
35
-     */
36
-    public function updating($model)
37
-    {
38
-        if ($model->getOriginal('name') == 'Admin') {
39
-            \Errors::noPermissions();
40
-        }
41
-    }
30
+	/**
31
+	 * Prevent updating of the admin role.
32
+	 *
33
+	 * @param  object $model the model beign updated.
34
+	 * @return void
35
+	 */
36
+	public function updating($model)
37
+	{
38
+		if ($model->getOriginal('name') == 'Admin') {
39
+			\Errors::noPermissions();
40
+		}
41
+	}
42 42
 
43
-    public function updated($model)
44
-    {
45
-        //
46
-    }
43
+	public function updated($model)
44
+	{
45
+		//
46
+	}
47 47
 
48
-    /**
49
-     * Prevent deleting the admin role.
50
-     *
51
-     * @param  object $model the delted model.
52
-     * @return void
53
-     */
54
-    public function deleting($model)
55
-    {
56
-        if ($model->getOriginal('name') == 'Admin') {
57
-            \Errors::noPermissions();
58
-        }
59
-    }
48
+	/**
49
+	 * Prevent deleting the admin role.
50
+	 *
51
+	 * @param  object $model the delted model.
52
+	 * @return void
53
+	 */
54
+	public function deleting($model)
55
+	{
56
+		if ($model->getOriginal('name') == 'Admin') {
57
+			\Errors::noPermissions();
58
+		}
59
+	}
60 60
 
61
-    public function deleted($model)
62
-    {
63
-        //
64
-    }
61
+	public function deleted($model)
62
+	{
63
+		//
64
+	}
65 65
 
66
-    public function restoring($model)
67
-    {
68
-        //
69
-    }
66
+	public function restoring($model)
67
+	{
68
+		//
69
+	}
70 70
 
71
-    public function restored($model)
72
-    {
73
-        //
74
-    }
71
+	public function restored($model)
72
+	{
73
+		//
74
+	}
75 75
 }
Please login to merge, or discard this patch.
src/Modules/Users/Resources/Lang/en/errors.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your error messages.
7
-     */
8
-    'unAuthorized'            => 'Please login before any action',
9
-    'invalidRefreshToken'     => 'Invalid refresh token',
10
-    'noPermissions'           => 'No permissions',
11
-    'loginFailed'             => 'Wrong mail or password',
12
-    'noSocialEmail'           => 'Couldn\'t retrieve email',
13
-    'userAlreadyRegistered'   => 'User already registered. Please login using email and password',
14
-    'userIsBlocked'           => 'You have been blocked',
15
-    'invalidResetToken'       => 'Reset password token is invalid',
16
-    'invalidResetPassword'    => 'Reset password is invalid',
17
-    'invalidOldPassword'      => 'Old password is invalid',
18
-    'invalidConfirmationCode' => 'Confirmation link expired or already used',
19
-    'emailNotConfirmed'       => 'Your email isn\'t confirmed',
20
-    'emailAlreadyConfirmed'   => 'Your email is already confirmed'
5
+	/**
6
+	 * Here goes your error messages.
7
+	 */
8
+	'unAuthorized'            => 'Please login before any action',
9
+	'invalidRefreshToken'     => 'Invalid refresh token',
10
+	'noPermissions'           => 'No permissions',
11
+	'loginFailed'             => 'Wrong mail or password',
12
+	'noSocialEmail'           => 'Couldn\'t retrieve email',
13
+	'userAlreadyRegistered'   => 'User already registered. Please login using email and password',
14
+	'userIsBlocked'           => 'You have been blocked',
15
+	'invalidResetToken'       => 'Reset password token is invalid',
16
+	'invalidResetPassword'    => 'Reset password is invalid',
17
+	'invalidOldPassword'      => 'Old password is invalid',
18
+	'invalidConfirmationCode' => 'Confirmation link expired or already used',
19
+	'emailNotConfirmed'       => 'Your email isn\'t confirmed',
20
+	'emailAlreadyConfirmed'   => 'Your email is already confirmed'
21 21
 
22 22
 ];
Please login to merge, or discard this patch.
src/Modules/Users/Resources/Lang/ar/errors.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -2,21 +2,21 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your error messages.
7
-     */
8
-    'unAuthorized'            => 'من فضلك قم بتسجيل الدخول',
9
-    'invalidRefreshToken'     => 'رمز التحديث غير صالح',
10
-    'noPermissions'           => 'لا توجد صلاحية',
11
-    'loginFailed'             => 'خطأ في البريد لاكتروني او كلمة المرور',
12
-    'noSocialEmail'           => 'لا يمكن الحصول علي تابريد الاكتروني',
13
-    'userAlreadyRegistered'   => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر',
14
-    'userIsBlocked'           => 'لقد تم حظرك',
15
-    'invalidResetToken'       => 'رمز تعديل كلمة المرور خطا',
16
-    'invalidResetPassword'    => 'خطا في نعديل كلمة المرور',
17
-    'invalidOldPassword'      => 'كلمة السر القديمه خطا',
18
-    'invalidConfirmationCode' => 'لينك التاكيد غير صالح اة مستخدم من قبل',
19
-    'emailNotConfirmed'       => 'بريدك الاكتروني غير مفعل',
20
-    'emailAlreadyConfirmed'   => 'البريد الاكتروني مفع بالقعل'
5
+	/**
6
+	 * Here goes your error messages.
7
+	 */
8
+	'unAuthorized'            => 'من فضلك قم بتسجيل الدخول',
9
+	'invalidRefreshToken'     => 'رمز التحديث غير صالح',
10
+	'noPermissions'           => 'لا توجد صلاحية',
11
+	'loginFailed'             => 'خطأ في البريد لاكتروني او كلمة المرور',
12
+	'noSocialEmail'           => 'لا يمكن الحصول علي تابريد الاكتروني',
13
+	'userAlreadyRegistered'   => 'المستخد مسجل بالفعل.سجل الدخول بالبريد الاكتروني و كلمة السر',
14
+	'userIsBlocked'           => 'لقد تم حظرك',
15
+	'invalidResetToken'       => 'رمز تعديل كلمة المرور خطا',
16
+	'invalidResetPassword'    => 'خطا في نعديل كلمة المرور',
17
+	'invalidOldPassword'      => 'كلمة السر القديمه خطا',
18
+	'invalidConfirmationCode' => 'لينك التاكيد غير صالح اة مستخدم من قبل',
19
+	'emailNotConfirmed'       => 'بريدك الاكتروني غير مفعل',
20
+	'emailAlreadyConfirmed'   => 'البريد الاكتروني مفع بالقعل'
21 21
 
22 22
 ];
Please login to merge, or discard this patch.
src/Modules/Users/Http/Controllers/UserController.php 1 patch
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -24,225 +24,225 @@
 block discarded – undo
24 24
 
25 25
 class UserController extends BaseApiController
26 26
 {
27
-    /**
28
-     * Path of the model resource
29
-     *
30
-     * @var string
31
-     */
32
-    protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser';
33
-
34
-    /**
35
-     * List of all route actions that the base api controller
36
-     * will skip permissions check for them.
37
-     * @var array
38
-     */
39
-    protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile'];
40
-
41
-    /**
42
-     * List of all route actions that the base api controller
43
-     * will skip login check for them.
44
-     * @var array
45
-     */
46
-    protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation'];
47
-
48
-    /**
49
-     * Init new object.
50
-     *
51
-     * @param   UserService $service
52
-     * @return  void
53
-     */
54
-    public function __construct(UserService $service)
55
-    {
56
-        parent::__construct($service);
57
-    }
58
-
59
-    /**
60
-     * Insert the given model to storage.
61
-     *
62
-     * @param InsertUser $request
63
-     * @return \Illuminate\Http\Response
64
-     */
65
-    public function insert(InsertUser $request)
66
-    {
67
-        return new $this->modelResource($this->service->save($request->all()));
68
-    }
69
-
70
-    /**
71
-     * Update the given model to storage.
72
-     *
73
-     * @param UpdateUser $request
74
-     * @return \Illuminate\Http\Response
75
-     */
76
-    public function update(UpdateUser $request)
77
-    {
78
-        return new $this->modelResource($this->service->save($request->all()));
79
-    }
80
-
81
-    /**
82
-     * Return the logged in user account.
83
-     *
84
-     * @param Request $request
85
-     * @return \Illuminate\Http\Response
86
-     */
87
-    public function account(Request $request)
88
-    {
89
-        return new $this->modelResource($this->service->account($request->relations));
90
-    }
91
-
92
-    /**
93
-     * Block the user.
94
-     *
95
-     * @param  integer  $id Id of the user.
96
-     * @return \Illuminate\Http\Response
97
-     */
98
-    public function block($id)
99
-    {
100
-        return new $this->modelResource($this->service->block($id));
101
-    }
102
-
103
-    /**
104
-     * Unblock the user.
105
-     *
106
-     * @param  integer  $id Id of the user.
107
-     * @return \Illuminate\Http\Response
108
-     */
109
-    public function unblock($id)
110
-    {
111
-        return new $this->modelResource($this->service->unblock($id));
112
-    }
113
-
114
-    /**
115
-     * Logout the user.
116
-     *
117
-     * @return \Illuminate\Http\Response
118
-     */
119
-    public function logout()
120
-    {
121
-        return new GeneralResource($this->service->logout());
122
-    }
123
-
124
-    /**
125
-     * Handle a registration request.
126
-     *
127
-     * @param Register $request
128
-     * @return \Illuminate\Http\Response
129
-     */
130
-    public function register(Register $request)
131
-    {
132
-        return new $this->modelResource($this->service->register($request->get('name'), $request->get('email'), $request->get('password')));
133
-    }
134
-
135
-    /**
136
-     * Handle a login request to the application.
137
-     *
138
-     * @param Login $request
139
-     * @return \Illuminate\Http\Response
140
-     */
141
-    public function login(Login $request)
142
-    {
143
-        $result = $this->service->login($request->get('email'), $request->get('password'), $request->get('admin'));
144
-
145
-        return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
146
-    }
147
-
148
-    /**
149
-     * Handle a social login request of the none admin to the application.
150
-     *
151
-     * @param LoginSocial $request
152
-     * @return \Illuminate\Http\Response
153
-     */
154
-    public function loginSocial(LoginSocial $request)
155
-    {
156
-        $result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type'));
157
-
158
-        return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
159
-    }
160
-
161
-    /**
162
-     * Assign the given roles to the given user.
163
-     *
164
-     * @param AssignRoles $request
165
-     * @return \Illuminate\Http\Response
166
-     */
167
-    public function assignRoles(AssignRoles $request)
168
-    {
169
-        return new $this->modelResource($this->service->assignRoles($request->get('user_id'), $request->get('role_ids')));
170
-    }
171
-
172
-    /**
173
-     * Send a reset link to the given user.
174
-     *
175
-     * @param SendReset $request
176
-     * @return \Illuminate\Http\Response
177
-     */
178
-    public function sendReset(SendReset $request)
179
-    {
180
-        return new GeneralResource($this->service->sendReset($request->get('email')));
181
-    }
182
-
183
-    /**
184
-     * Reset the given user's password.
185
-     *
186
-     * @param ResetPassword $request
187
-     * @return \Illuminate\Http\Response
188
-     */
189
-    public function resetPassword(ResetPassword $request)
190
-    {
191
-        return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token')));
192
-    }
193
-
194
-    /**
195
-     * Change the logged in user password.
196
-     *
197
-     * @param ChangePassword $request
198
-     * @return \Illuminate\Http\Response
199
-     */
200
-    public function changePassword(ChangePassword $request)
201
-    {
202
-        return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password')));
203
-    }
204
-
205
-    /**
206
-     * Confirm email using the confirmation code.
207
-     *
208
-     * @param ConfirmEmail $request
209
-     * @return \Illuminate\Http\Response
210
-     */
211
-    public function confirmEmail(ConfirmEmail $request)
212
-    {
213
-        return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code')));
214
-    }
215
-
216
-    /**
217
-     * Resend the email confirmation mail.
218
-     *
219
-     * @param ResendEmailConfirmation $request
220
-     * @return \Illuminate\Http\Response
221
-     */
222
-    public function resendEmailConfirmation(ResendEmailConfirmation $request)
223
-    {
224
-        return new GeneralResource($this->service->sendConfirmationEmail($request->get('email')));
225
-    }
226
-
227
-    /**
228
-     * Refresh the expired login token.
229
-     *
230
-     * @param RefreshToken $request
231
-     * @return \Illuminate\Http\Response
232
-     */
233
-    public function refreshToken(RefreshToken $request)
234
-    {
235
-        return new GeneralResource($this->service->refreshToken($request->get('refresh_token')));
236
-    }
237
-
238
-    /**
239
-     * Save the given data to the logged in user.
240
-     *
241
-     * @param SaveProfile $request
242
-     * @return \Illuminate\Http\Response
243
-     */
244
-    public function saveProfile(SaveProfile $request)
245
-    {
246
-        return new $this->modelResource($this->service->saveProfile($request->get('name'), $request->get('email'), $request->get('profile_picture')));
247
-    }
27
+	/**
28
+	 * Path of the model resource
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected $modelResource = 'App\Modules\Users\Http\Resources\AclUser';
33
+
34
+	/**
35
+	 * List of all route actions that the base api controller
36
+	 * will skip permissions check for them.
37
+	 * @var array
38
+	 */
39
+	protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile'];
40
+
41
+	/**
42
+	 * List of all route actions that the base api controller
43
+	 * will skip login check for them.
44
+	 * @var array
45
+	 */
46
+	protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation'];
47
+
48
+	/**
49
+	 * Init new object.
50
+	 *
51
+	 * @param   UserService $service
52
+	 * @return  void
53
+	 */
54
+	public function __construct(UserService $service)
55
+	{
56
+		parent::__construct($service);
57
+	}
58
+
59
+	/**
60
+	 * Insert the given model to storage.
61
+	 *
62
+	 * @param InsertUser $request
63
+	 * @return \Illuminate\Http\Response
64
+	 */
65
+	public function insert(InsertUser $request)
66
+	{
67
+		return new $this->modelResource($this->service->save($request->all()));
68
+	}
69
+
70
+	/**
71
+	 * Update the given model to storage.
72
+	 *
73
+	 * @param UpdateUser $request
74
+	 * @return \Illuminate\Http\Response
75
+	 */
76
+	public function update(UpdateUser $request)
77
+	{
78
+		return new $this->modelResource($this->service->save($request->all()));
79
+	}
80
+
81
+	/**
82
+	 * Return the logged in user account.
83
+	 *
84
+	 * @param Request $request
85
+	 * @return \Illuminate\Http\Response
86
+	 */
87
+	public function account(Request $request)
88
+	{
89
+		return new $this->modelResource($this->service->account($request->relations));
90
+	}
91
+
92
+	/**
93
+	 * Block the user.
94
+	 *
95
+	 * @param  integer  $id Id of the user.
96
+	 * @return \Illuminate\Http\Response
97
+	 */
98
+	public function block($id)
99
+	{
100
+		return new $this->modelResource($this->service->block($id));
101
+	}
102
+
103
+	/**
104
+	 * Unblock the user.
105
+	 *
106
+	 * @param  integer  $id Id of the user.
107
+	 * @return \Illuminate\Http\Response
108
+	 */
109
+	public function unblock($id)
110
+	{
111
+		return new $this->modelResource($this->service->unblock($id));
112
+	}
113
+
114
+	/**
115
+	 * Logout the user.
116
+	 *
117
+	 * @return \Illuminate\Http\Response
118
+	 */
119
+	public function logout()
120
+	{
121
+		return new GeneralResource($this->service->logout());
122
+	}
123
+
124
+	/**
125
+	 * Handle a registration request.
126
+	 *
127
+	 * @param Register $request
128
+	 * @return \Illuminate\Http\Response
129
+	 */
130
+	public function register(Register $request)
131
+	{
132
+		return new $this->modelResource($this->service->register($request->get('name'), $request->get('email'), $request->get('password')));
133
+	}
134
+
135
+	/**
136
+	 * Handle a login request to the application.
137
+	 *
138
+	 * @param Login $request
139
+	 * @return \Illuminate\Http\Response
140
+	 */
141
+	public function login(Login $request)
142
+	{
143
+		$result = $this->service->login($request->get('email'), $request->get('password'), $request->get('admin'));
144
+
145
+		return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
146
+	}
147
+
148
+	/**
149
+	 * Handle a social login request of the none admin to the application.
150
+	 *
151
+	 * @param LoginSocial $request
152
+	 * @return \Illuminate\Http\Response
153
+	 */
154
+	public function loginSocial(LoginSocial $request)
155
+	{
156
+		$result = $this->service->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type'));
157
+
158
+		return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
159
+	}
160
+
161
+	/**
162
+	 * Assign the given roles to the given user.
163
+	 *
164
+	 * @param AssignRoles $request
165
+	 * @return \Illuminate\Http\Response
166
+	 */
167
+	public function assignRoles(AssignRoles $request)
168
+	{
169
+		return new $this->modelResource($this->service->assignRoles($request->get('user_id'), $request->get('role_ids')));
170
+	}
171
+
172
+	/**
173
+	 * Send a reset link to the given user.
174
+	 *
175
+	 * @param SendReset $request
176
+	 * @return \Illuminate\Http\Response
177
+	 */
178
+	public function sendReset(SendReset $request)
179
+	{
180
+		return new GeneralResource($this->service->sendReset($request->get('email')));
181
+	}
182
+
183
+	/**
184
+	 * Reset the given user's password.
185
+	 *
186
+	 * @param ResetPassword $request
187
+	 * @return \Illuminate\Http\Response
188
+	 */
189
+	public function resetPassword(ResetPassword $request)
190
+	{
191
+		return new GeneralResource($this->service->resetPassword($request->get('email'), $request->get('password'), $request->get('password_confirmation'), $request->get('token')));
192
+	}
193
+
194
+	/**
195
+	 * Change the logged in user password.
196
+	 *
197
+	 * @param ChangePassword $request
198
+	 * @return \Illuminate\Http\Response
199
+	 */
200
+	public function changePassword(ChangePassword $request)
201
+	{
202
+		return new GeneralResource($this->service->changePassword($request->get('password'), $request->get('old_password')));
203
+	}
204
+
205
+	/**
206
+	 * Confirm email using the confirmation code.
207
+	 *
208
+	 * @param ConfirmEmail $request
209
+	 * @return \Illuminate\Http\Response
210
+	 */
211
+	public function confirmEmail(ConfirmEmail $request)
212
+	{
213
+		return new GeneralResource($this->service->confirmEmail($request->only('confirmation_code')));
214
+	}
215
+
216
+	/**
217
+	 * Resend the email confirmation mail.
218
+	 *
219
+	 * @param ResendEmailConfirmation $request
220
+	 * @return \Illuminate\Http\Response
221
+	 */
222
+	public function resendEmailConfirmation(ResendEmailConfirmation $request)
223
+	{
224
+		return new GeneralResource($this->service->sendConfirmationEmail($request->get('email')));
225
+	}
226
+
227
+	/**
228
+	 * Refresh the expired login token.
229
+	 *
230
+	 * @param RefreshToken $request
231
+	 * @return \Illuminate\Http\Response
232
+	 */
233
+	public function refreshToken(RefreshToken $request)
234
+	{
235
+		return new GeneralResource($this->service->refreshToken($request->get('refresh_token')));
236
+	}
237
+
238
+	/**
239
+	 * Save the given data to the logged in user.
240
+	 *
241
+	 * @param SaveProfile $request
242
+	 * @return \Illuminate\Http\Response
243
+	 */
244
+	public function saveProfile(SaveProfile $request)
245
+	{
246
+		return new $this->modelResource($this->service->saveProfile($request->get('name'), $request->get('email'), $request->get('profile_picture')));
247
+	}
248 248
 }
Please login to merge, or discard this patch.
src/Modules/Users/Errors/UsersErrors.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -4,68 +4,68 @@
 block discarded – undo
4 4
 
5 5
 class UsersErrors
6 6
 {
7
-    public function unAuthorized()
8
-    {
9
-        abort(401, trans('users::errors.unAuthorized'));
10
-    }
7
+	public function unAuthorized()
8
+	{
9
+		abort(401, trans('users::errors.unAuthorized'));
10
+	}
11 11
 
12
-    public function noPermissions()
13
-    {
14
-        abort(403, trans('users::errors.noPermissions'));
15
-    }
12
+	public function noPermissions()
13
+	{
14
+		abort(403, trans('users::errors.noPermissions'));
15
+	}
16 16
 
17
-    public function userIsBlocked()
18
-    {
19
-        abort(403, trans('users::errors.userIsBlocked'));
20
-    }
17
+	public function userIsBlocked()
18
+	{
19
+		abort(403, trans('users::errors.userIsBlocked'));
20
+	}
21 21
 
22
-    public function emailNotConfirmed()
23
-    {
24
-        abort(403, trans('users::errors.emailNotConfirmed'));
25
-    }
22
+	public function emailNotConfirmed()
23
+	{
24
+		abort(403, trans('users::errors.emailNotConfirmed'));
25
+	}
26 26
 
27
-    public function loginFailed()
28
-    {
29
-        abort(400, trans('users::errors.loginFailed'));
30
-    }
27
+	public function loginFailed()
28
+	{
29
+		abort(400, trans('users::errors.loginFailed'));
30
+	}
31 31
 
32
-    public function emailAlreadyConfirmed()
33
-    {
34
-        abort(400, trans('users::errors.emailAlreadyConfirmed'));
35
-    }
32
+	public function emailAlreadyConfirmed()
33
+	{
34
+		abort(400, trans('users::errors.emailAlreadyConfirmed'));
35
+	}
36 36
 
37
-    public function noSocialEmail()
38
-    {
39
-        abort(400, trans('users::errors.noSocialEmail'));
40
-    }
37
+	public function noSocialEmail()
38
+	{
39
+		abort(400, trans('users::errors.noSocialEmail'));
40
+	}
41 41
 
42
-    public function userAlreadyRegistered()
43
-    {
44
-        abort(400, trans('users::errors.userAlreadyRegistered'));
45
-    }
42
+	public function userAlreadyRegistered()
43
+	{
44
+		abort(400, trans('users::errors.userAlreadyRegistered'));
45
+	}
46 46
 
47
-    public function invalidRefreshToken()
48
-    {
49
-        abort(422, trans('users::errors.invalidRefreshToken'));
50
-    }
47
+	public function invalidRefreshToken()
48
+	{
49
+		abort(422, trans('users::errors.invalidRefreshToken'));
50
+	}
51 51
 
52
-    public function invalidResetToken()
53
-    {
54
-        abort(422, trans('users::errors.invalidResetToken'));
55
-    }
52
+	public function invalidResetToken()
53
+	{
54
+		abort(422, trans('users::errors.invalidResetToken'));
55
+	}
56 56
 
57
-    public function invalidResetPassword()
58
-    {
59
-        abort(422, trans('users::errors.invalidResetPassword'));
60
-    }
57
+	public function invalidResetPassword()
58
+	{
59
+		abort(422, trans('users::errors.invalidResetPassword'));
60
+	}
61 61
 
62
-    public function invalidOldPassword()
63
-    {
64
-        abort(422, trans('users::errors.invalidOldPassword'));
65
-    }
62
+	public function invalidOldPassword()
63
+	{
64
+		abort(422, trans('users::errors.invalidOldPassword'));
65
+	}
66 66
 
67
-    public function invalidConfirmationCode()
68
-    {
69
-        abort(422, trans('users::errors.invalidConfirmationCode'));
70
-    }
67
+	public function invalidConfirmationCode()
68
+	{
69
+		abort(422, trans('users::errors.invalidConfirmationCode'));
70
+	}
71 71
 }
Please login to merge, or discard this patch.
src/Modules/Users/Services/UserService.php 2 patches
Indentation   +370 added lines, -370 removed lines patch added patch discarded remove patch
@@ -12,378 +12,378 @@
 block discarded – undo
12 12
 
13 13
 class UserService extends BaseService
14 14
 {
15
-    /**
16
-     * @var PermissionService
17
-     */
18
-    protected $permissionService;
19
-
20
-    /**
21
-     * @var LoginProxy
22
-     */
23
-    protected $loginProxy;
24
-
25
-    /**
26
-     * @var NotificationService
27
-     */
28
-    protected $notificationService;
29
-
30
-    /**
31
-     * @var OauthClientService
32
-     */
33
-    protected $oauthClientService;
34
-
35
-    /**
36
-     * Init new object.
37
-     *
38
-     * @param   UserRepository       $repo
39
-     * @param   PermissionService    $permissionService
40
-     * @param   LoginProxy           $loginProxy
41
-     * @param   NotificationService  $notificationService
42
-     * @param   OauthClientService   $oauthClientService
43
-     * @return  void
44
-     */
45
-    public function __construct(
46
-        UserRepository $repo,
47
-        PermissionService $permissionService,
48
-        LoginProxy $loginProxy,
49
-        NotificationService $notificationService,
50
-        OauthClientService $oauthClientService
51
-    ) {
52
-        $this->permissionService   = $permissionService;
53
-        $this->loginProxy          = $loginProxy;
54
-        $this->notificationService = $notificationService;
55
-        $this->oauthClientService  = $oauthClientService;
56
-        parent::__construct($repo);
57
-    }
58
-
59
-    /**
60
-     * Return the logged in user account.
61
-     *
62
-     * @param  array   $relations
63
-     * @return boolean
64
-     */
65
-    public function account($relations = ['roles.permissions'])
66
-    {
67
-        $permissions = [];
68
-        $user        = $this->repo->find(\Auth::id(), $relations);
69
-        foreach ($user->roles as $role) {
70
-            $role->permissions->each(function ($permission) use (&$permissions) {
71
-                $permissions[$permission->repo][$permission->id] = $permission->name;
72
-            });
73
-        }
74
-        $user->permissions = $permissions;
75
-
76
-        return $user;
77
-    }
78
-
79
-    /**
80
-     * Check if the logged in user or the given user
81
-     * has the given permissions on the given model.
82
-     *
83
-     * @param  string $permissionName
84
-     * @param  string $model
85
-     * @param  mixed  $userId
86
-     * @return boolean
87
-     */
88
-    public function can($permissionName, $model, $userId = false)
89
-    {
90
-        $permission = $this->permissionService->first([
91
-            'and' => [
92
-                'model' => $model,
93
-                'name'  => $permissionName,
94
-                'roles' => [
95
-                    'op' => 'has',
96
-                    'val' => [
97
-                        'users' => [
98
-                            'op' => 'has',
99
-                            'val' => [
100
-                                'users.id' => $userId ?: \Auth::id()
101
-                            ]
102
-                        ]
103
-                    ]
104
-                ]
105
-            ]
106
-        ]);
107
-
108
-        return $permission ? true : false;
109
-    }
110
-
111
-    /**
112
-     * Check if the logged in or the given user has the given role.
113
-     *
114
-     * @param  string[] $roles
115
-     * @param  mixed    $user
116
-     * @return boolean
117
-     */
118
-    public function hasRoles($roles, $user = false)
119
-    {
120
-        return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false;
121
-    }
122
-
123
-    /**
124
-     * Assign the given role ids to the given user.
125
-     *
126
-     * @param  integer $userId
127
-     * @param  array   $roleIds
128
-     * @return object
129
-     */
130
-    public function assignRoles($userId, $roleIds)
131
-    {
132
-        $user = false;
133
-        \DB::transaction(function () use ($userId, $roleIds, &$user) {
134
-            $user = $this->repo->find($userId);
135
-            $this->repo->detachPermissions($userId);
136
-            $this->repo->attachPermissions($userId, $roleIds);
137
-        });
138
-
139
-        return $user;
140
-    }
141
-
142
-    /**
143
-     * Handle a login request to the application.
144
-     *
145
-     * @param  string  $email
146
-     * @param  string  $password
147
-     * @param  boolean $adminLogin
148
-     * @return object
149
-     */
150
-    public function login($email, $password, $adminLogin = false)
151
-    {
152
-        if (! $user = $this->repo->first(['email' => $email])) {
153
-            \Errors::loginFailed();
154
-        } elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) {
155
-            \Errors::loginFailed();
156
-        } elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) {
157
-            \Errors::loginFailed();
158
-        } elseif ($user->blocked) {
159
-            \Errors::userIsBlocked();
160
-        } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
161
-            \Errors::emailNotConfirmed();
162
-        }
163
-
164
-        return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)];
165
-    }
166
-
167
-    /**
168
-     * Handle a social login request of the none admin to the application.
169
-     *
170
-     * @param  string $authCode
171
-     * @param  string $accessToken
172
-     * @param  string $type
173
-     * @return array
174
-     */
175
-    public function loginSocial($authCode, $accessToken, $type)
176
-    {
177
-        $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
178
-        $user         = \Socialite::driver($type)->userFromToken($access_token);
179
-
180
-        if (! $user->email) {
181
-            \Errors::noSocialEmail();
182
-        }
183
-
184
-        if (! $this->repo->first(['email' => $user->email])) {
185
-            $this->register($user->email, '', true);
186
-        }
187
-
188
-        return $this->loginProxy->login($user->email, config('skeleton.social_pass'));
189
-    }
15
+	/**
16
+	 * @var PermissionService
17
+	 */
18
+	protected $permissionService;
19
+
20
+	/**
21
+	 * @var LoginProxy
22
+	 */
23
+	protected $loginProxy;
24
+
25
+	/**
26
+	 * @var NotificationService
27
+	 */
28
+	protected $notificationService;
29
+
30
+	/**
31
+	 * @var OauthClientService
32
+	 */
33
+	protected $oauthClientService;
34
+
35
+	/**
36
+	 * Init new object.
37
+	 *
38
+	 * @param   UserRepository       $repo
39
+	 * @param   PermissionService    $permissionService
40
+	 * @param   LoginProxy           $loginProxy
41
+	 * @param   NotificationService  $notificationService
42
+	 * @param   OauthClientService   $oauthClientService
43
+	 * @return  void
44
+	 */
45
+	public function __construct(
46
+		UserRepository $repo,
47
+		PermissionService $permissionService,
48
+		LoginProxy $loginProxy,
49
+		NotificationService $notificationService,
50
+		OauthClientService $oauthClientService
51
+	) {
52
+		$this->permissionService   = $permissionService;
53
+		$this->loginProxy          = $loginProxy;
54
+		$this->notificationService = $notificationService;
55
+		$this->oauthClientService  = $oauthClientService;
56
+		parent::__construct($repo);
57
+	}
58
+
59
+	/**
60
+	 * Return the logged in user account.
61
+	 *
62
+	 * @param  array   $relations
63
+	 * @return boolean
64
+	 */
65
+	public function account($relations = ['roles.permissions'])
66
+	{
67
+		$permissions = [];
68
+		$user        = $this->repo->find(\Auth::id(), $relations);
69
+		foreach ($user->roles as $role) {
70
+			$role->permissions->each(function ($permission) use (&$permissions) {
71
+				$permissions[$permission->repo][$permission->id] = $permission->name;
72
+			});
73
+		}
74
+		$user->permissions = $permissions;
75
+
76
+		return $user;
77
+	}
78
+
79
+	/**
80
+	 * Check if the logged in user or the given user
81
+	 * has the given permissions on the given model.
82
+	 *
83
+	 * @param  string $permissionName
84
+	 * @param  string $model
85
+	 * @param  mixed  $userId
86
+	 * @return boolean
87
+	 */
88
+	public function can($permissionName, $model, $userId = false)
89
+	{
90
+		$permission = $this->permissionService->first([
91
+			'and' => [
92
+				'model' => $model,
93
+				'name'  => $permissionName,
94
+				'roles' => [
95
+					'op' => 'has',
96
+					'val' => [
97
+						'users' => [
98
+							'op' => 'has',
99
+							'val' => [
100
+								'users.id' => $userId ?: \Auth::id()
101
+							]
102
+						]
103
+					]
104
+				]
105
+			]
106
+		]);
107
+
108
+		return $permission ? true : false;
109
+	}
110
+
111
+	/**
112
+	 * Check if the logged in or the given user has the given role.
113
+	 *
114
+	 * @param  string[] $roles
115
+	 * @param  mixed    $user
116
+	 * @return boolean
117
+	 */
118
+	public function hasRoles($roles, $user = false)
119
+	{
120
+		return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false;
121
+	}
122
+
123
+	/**
124
+	 * Assign the given role ids to the given user.
125
+	 *
126
+	 * @param  integer $userId
127
+	 * @param  array   $roleIds
128
+	 * @return object
129
+	 */
130
+	public function assignRoles($userId, $roleIds)
131
+	{
132
+		$user = false;
133
+		\DB::transaction(function () use ($userId, $roleIds, &$user) {
134
+			$user = $this->repo->find($userId);
135
+			$this->repo->detachPermissions($userId);
136
+			$this->repo->attachPermissions($userId, $roleIds);
137
+		});
138
+
139
+		return $user;
140
+	}
141
+
142
+	/**
143
+	 * Handle a login request to the application.
144
+	 *
145
+	 * @param  string  $email
146
+	 * @param  string  $password
147
+	 * @param  boolean $adminLogin
148
+	 * @return object
149
+	 */
150
+	public function login($email, $password, $adminLogin = false)
151
+	{
152
+		if (! $user = $this->repo->first(['email' => $email])) {
153
+			\Errors::loginFailed();
154
+		} elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) {
155
+			\Errors::loginFailed();
156
+		} elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) {
157
+			\Errors::loginFailed();
158
+		} elseif ($user->blocked) {
159
+			\Errors::userIsBlocked();
160
+		} elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
161
+			\Errors::emailNotConfirmed();
162
+		}
163
+
164
+		return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)];
165
+	}
166
+
167
+	/**
168
+	 * Handle a social login request of the none admin to the application.
169
+	 *
170
+	 * @param  string $authCode
171
+	 * @param  string $accessToken
172
+	 * @param  string $type
173
+	 * @return array
174
+	 */
175
+	public function loginSocial($authCode, $accessToken, $type)
176
+	{
177
+		$access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
178
+		$user         = \Socialite::driver($type)->userFromToken($access_token);
179
+
180
+		if (! $user->email) {
181
+			\Errors::noSocialEmail();
182
+		}
183
+
184
+		if (! $this->repo->first(['email' => $user->email])) {
185
+			$this->register($user->email, '', true);
186
+		}
187
+
188
+		return $this->loginProxy->login($user->email, config('skeleton.social_pass'));
189
+	}
190 190
     
191
-    /**
192
-     * Handle a registration request.
193
-     *
194
-     * @param  string  $name
195
-     * @param  string  $email
196
-     * @param  string  $password
197
-     * @param  boolean $skipConfirmEmail
198
-     * @return array
199
-     */
200
-    public function register($name, $email, $password, $skipConfirmEmail = false)
201
-    {
202
-        $user = $this->repo->save([
203
-            'name'      => $name,
204
-            'email'     => $email,
205
-            'password'  => $password,
206
-            'confirmed' => $skipConfirmEmail
207
-        ]);
208
-
209
-        if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
210
-            $this->sendConfirmationEmail($user->email);
211
-        }
212
-
213
-        return $user;
214
-    }
191
+	/**
192
+	 * Handle a registration request.
193
+	 *
194
+	 * @param  string  $name
195
+	 * @param  string  $email
196
+	 * @param  string  $password
197
+	 * @param  boolean $skipConfirmEmail
198
+	 * @return array
199
+	 */
200
+	public function register($name, $email, $password, $skipConfirmEmail = false)
201
+	{
202
+		$user = $this->repo->save([
203
+			'name'      => $name,
204
+			'email'     => $email,
205
+			'password'  => $password,
206
+			'confirmed' => $skipConfirmEmail
207
+		]);
208
+
209
+		if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
210
+			$this->sendConfirmationEmail($user->email);
211
+		}
212
+
213
+		return $user;
214
+	}
215 215
     
216
-    /**
217
-     * Block the user.
218
-     *
219
-     * @param  integer $userId
220
-     * @return object
221
-     */
222
-    public function block($userId)
223
-    {
224
-        if (\Auth::id() == $userId || $this->hasRoles(['Admin'], $user) !== false) {
225
-            \Errors::noPermissions();
226
-        }
216
+	/**
217
+	 * Block the user.
218
+	 *
219
+	 * @param  integer $userId
220
+	 * @return object
221
+	 */
222
+	public function block($userId)
223
+	{
224
+		if (\Auth::id() == $userId || $this->hasRoles(['Admin'], $user) !== false) {
225
+			\Errors::noPermissions();
226
+		}
227 227
         
228
-        return $this->repo->save(['id' => $userId, 'blocked' => 1]);
229
-    }
230
-
231
-    /**
232
-     * Unblock the user.
233
-     *
234
-     * @param  integer $userId
235
-     * @return object
236
-     */
237
-    public function unblock($userId)
238
-    {
239
-        return $this->repo->save(['id' => $userId, 'blocked' => 0]);
240
-    }
241
-
242
-    /**
243
-     * Send a reset link to the given user.
244
-     *
245
-     * @param  string  $email
246
-     * @return void
247
-     */
248
-    public function sendReset($email)
249
-    {
250
-        if (! $user = $this->repo->first(['email' => $email])) {
251
-            \Errors::notFound('email');
252
-        }
253
-
254
-        $token = \Password::getService()->create($user);
255
-        $this->notificationService->notify($user, 'ResetPassword', $token);
256
-    }
257
-
258
-    /**
259
-     * Reset the given user's password.
260
-     *
261
-     * @param   string  $email
262
-     * @param   string  $password
263
-     * @param   string  $passwordConfirmation
264
-     * @param   string  $token
265
-     * @return string|void
266
-     */
267
-    public function resetPassword($email, $password, $passwordConfirmation, $token)
268
-    {
269
-        $response = \Password::reset([
270
-            'email'                 => $email,
271
-            'password'              => $password,
272
-            'password_confirmation' => $passwordConfirmation,
273
-            'token'                 => $token
274
-        ], function ($user, $password) {
275
-            $this->repo->save(['id' => $user->id, 'password' => $password]);
276
-        });
277
-
278
-        switch ($response) {
279
-            case \Password::PASSWORD_RESET:
280
-                return 'success';
281
-                break;
282
-
283
-            case \Password::INVALID_TOKEN:
284
-                \Errors::invalidResetToken();
285
-                break;
286
-
287
-            case \Password::INVALID_PASSWORD:
288
-                \Errors::invalidResetPassword();
289
-                break;
290
-
291
-            case \Password::INVALID_USER:
292
-                \Errors::notFound('user');
293
-                break;
294
-        }
295
-    }
296
-
297
-    /**
298
-     * Change the logged in user password.
299
-     *
300
-     * @param  string  $password
301
-     * @param  string  $oldPassword
302
-     * @return void
303
-     */
304
-    public function changePassword($password, $oldPassword)
305
-    {
306
-        $user = \Auth::user();
307
-        if (! \Hash::check($oldPassword, $user->password)) {
308
-            \Errors::invalidOldPassword();
309
-        }
310
-
311
-        $this->repo->save(['id' => $user->id, 'password' => $password]);
312
-    }
313
-
314
-    /**
315
-     * Confirm email using the confirmation code.
316
-     *
317
-     * @param  string $confirmationCode
318
-     * @return void
319
-     */
320
-    public function confirmEmail($confirmationCode)
321
-    {
322
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
323
-            \Errors::invalidConfirmationCode();
324
-        }
325
-
326
-        $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
327
-    }
328
-
329
-    /**
330
-     * Send the confirmation mail.
331
-     *
332
-     * @param  string $email
333
-     * @return void
334
-     */
335
-    public function sendConfirmationEmail($email)
336
-    {
337
-        $user = $this->repo->first(['email' => $email]);
338
-        if ($user->confirmed) {
339
-            \Errors::emailAlreadyConfirmed();
340
-        }
341
-
342
-        $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
343
-        $this->notificationService->notify($user, 'ConfirmEmail');
344
-    }
345
-
346
-    /**
347
-     * Save the given data to the logged in user.
348
-     *
349
-     * @param  string $name
350
-     * @param  string $email
351
-     * @param  string $profilePicture
352
-     * @return void
353
-     */
354
-    public function saveProfile($name, $email, $profilePicture = false)
355
-    {
356
-        if ($profilePicture) {
357
-            $data['profile_picture'] = \Media::uploadImageBas64($profilePicture, 'admins/profile_pictures');
358
-        }
228
+		return $this->repo->save(['id' => $userId, 'blocked' => 1]);
229
+	}
230
+
231
+	/**
232
+	 * Unblock the user.
233
+	 *
234
+	 * @param  integer $userId
235
+	 * @return object
236
+	 */
237
+	public function unblock($userId)
238
+	{
239
+		return $this->repo->save(['id' => $userId, 'blocked' => 0]);
240
+	}
241
+
242
+	/**
243
+	 * Send a reset link to the given user.
244
+	 *
245
+	 * @param  string  $email
246
+	 * @return void
247
+	 */
248
+	public function sendReset($email)
249
+	{
250
+		if (! $user = $this->repo->first(['email' => $email])) {
251
+			\Errors::notFound('email');
252
+		}
253
+
254
+		$token = \Password::getService()->create($user);
255
+		$this->notificationService->notify($user, 'ResetPassword', $token);
256
+	}
257
+
258
+	/**
259
+	 * Reset the given user's password.
260
+	 *
261
+	 * @param   string  $email
262
+	 * @param   string  $password
263
+	 * @param   string  $passwordConfirmation
264
+	 * @param   string  $token
265
+	 * @return string|void
266
+	 */
267
+	public function resetPassword($email, $password, $passwordConfirmation, $token)
268
+	{
269
+		$response = \Password::reset([
270
+			'email'                 => $email,
271
+			'password'              => $password,
272
+			'password_confirmation' => $passwordConfirmation,
273
+			'token'                 => $token
274
+		], function ($user, $password) {
275
+			$this->repo->save(['id' => $user->id, 'password' => $password]);
276
+		});
277
+
278
+		switch ($response) {
279
+			case \Password::PASSWORD_RESET:
280
+				return 'success';
281
+				break;
282
+
283
+			case \Password::INVALID_TOKEN:
284
+				\Errors::invalidResetToken();
285
+				break;
286
+
287
+			case \Password::INVALID_PASSWORD:
288
+				\Errors::invalidResetPassword();
289
+				break;
290
+
291
+			case \Password::INVALID_USER:
292
+				\Errors::notFound('user');
293
+				break;
294
+		}
295
+	}
296
+
297
+	/**
298
+	 * Change the logged in user password.
299
+	 *
300
+	 * @param  string  $password
301
+	 * @param  string  $oldPassword
302
+	 * @return void
303
+	 */
304
+	public function changePassword($password, $oldPassword)
305
+	{
306
+		$user = \Auth::user();
307
+		if (! \Hash::check($oldPassword, $user->password)) {
308
+			\Errors::invalidOldPassword();
309
+		}
310
+
311
+		$this->repo->save(['id' => $user->id, 'password' => $password]);
312
+	}
313
+
314
+	/**
315
+	 * Confirm email using the confirmation code.
316
+	 *
317
+	 * @param  string $confirmationCode
318
+	 * @return void
319
+	 */
320
+	public function confirmEmail($confirmationCode)
321
+	{
322
+		if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
323
+			\Errors::invalidConfirmationCode();
324
+		}
325
+
326
+		$this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
327
+	}
328
+
329
+	/**
330
+	 * Send the confirmation mail.
331
+	 *
332
+	 * @param  string $email
333
+	 * @return void
334
+	 */
335
+	public function sendConfirmationEmail($email)
336
+	{
337
+		$user = $this->repo->first(['email' => $email]);
338
+		if ($user->confirmed) {
339
+			\Errors::emailAlreadyConfirmed();
340
+		}
341
+
342
+		$this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
343
+		$this->notificationService->notify($user, 'ConfirmEmail');
344
+	}
345
+
346
+	/**
347
+	 * Save the given data to the logged in user.
348
+	 *
349
+	 * @param  string $name
350
+	 * @param  string $email
351
+	 * @param  string $profilePicture
352
+	 * @return void
353
+	 */
354
+	public function saveProfile($name, $email, $profilePicture = false)
355
+	{
356
+		if ($profilePicture) {
357
+			$data['profile_picture'] = \Media::uploadImageBas64($profilePicture, 'admins/profile_pictures');
358
+		}
359 359
         
360
-        $data['id'] = \Auth::id();
361
-        return $this->repo->save([
362
-            'id'             => \Auth::id(),
363
-            'name'           => $name,
364
-            'email'          => $email,
365
-            'profilePicture' => $profilePicture,
366
-        ]);
367
-    }
368
-
369
-    /**
370
-     * Logs out the user, revoke access token and refresh token.
371
-     *
372
-     * @return void
373
-     */
374
-    public function logout()
375
-    {
376
-        $this->oauthClientService->revokeAccessToken(\Auth::user()->token());
377
-    }
378
-
379
-    /**
380
-     * Attempt to refresh the access token using the given refresh token.
381
-     *
382
-     * @param  string $refreshToken
383
-     * @return array
384
-     */
385
-    public function refreshToken($refreshToken)
386
-    {
387
-        return $this->loginProxy->refreshToken($refreshToken);
388
-    }
360
+		$data['id'] = \Auth::id();
361
+		return $this->repo->save([
362
+			'id'             => \Auth::id(),
363
+			'name'           => $name,
364
+			'email'          => $email,
365
+			'profilePicture' => $profilePicture,
366
+		]);
367
+	}
368
+
369
+	/**
370
+	 * Logs out the user, revoke access token and refresh token.
371
+	 *
372
+	 * @return void
373
+	 */
374
+	public function logout()
375
+	{
376
+		$this->oauthClientService->revokeAccessToken(\Auth::user()->token());
377
+	}
378
+
379
+	/**
380
+	 * Attempt to refresh the access token using the given refresh token.
381
+	 *
382
+	 * @param  string $refreshToken
383
+	 * @return array
384
+	 */
385
+	public function refreshToken($refreshToken)
386
+	{
387
+		return $this->loginProxy->refreshToken($refreshToken);
388
+	}
389 389
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $permissions = [];
68 68
         $user        = $this->repo->find(\Auth::id(), $relations);
69 69
         foreach ($user->roles as $role) {
70
-            $role->permissions->each(function ($permission) use (&$permissions) {
70
+            $role->permissions->each(function($permission) use (&$permissions) {
71 71
                 $permissions[$permission->repo][$permission->id] = $permission->name;
72 72
             });
73 73
         }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     public function assignRoles($userId, $roleIds)
131 131
     {
132 132
         $user = false;
133
-        \DB::transaction(function () use ($userId, $roleIds, &$user) {
133
+        \DB::transaction(function() use ($userId, $roleIds, &$user) {
134 134
             $user = $this->repo->find($userId);
135 135
             $this->repo->detachPermissions($userId);
136 136
             $this->repo->attachPermissions($userId, $roleIds);
@@ -149,15 +149,15 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function login($email, $password, $adminLogin = false)
151 151
     {
152
-        if (! $user = $this->repo->first(['email' => $email])) {
152
+        if ( ! $user = $this->repo->first(['email' => $email])) {
153 153
             \Errors::loginFailed();
154 154
         } elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) {
155 155
             \Errors::loginFailed();
156
-        } elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) {
156
+        } elseif ( ! $adminLogin && $this->hasRoles(['Admin'], $user)) {
157 157
             \Errors::loginFailed();
158 158
         } elseif ($user->blocked) {
159 159
             \Errors::userIsBlocked();
160
-        } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
160
+        } elseif ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
161 161
             \Errors::emailNotConfirmed();
162 162
         }
163 163
 
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
         $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
178 178
         $user         = \Socialite::driver($type)->userFromToken($access_token);
179 179
 
180
-        if (! $user->email) {
180
+        if ( ! $user->email) {
181 181
             \Errors::noSocialEmail();
182 182
         }
183 183
 
184
-        if (! $this->repo->first(['email' => $user->email])) {
184
+        if ( ! $this->repo->first(['email' => $user->email])) {
185 185
             $this->register($user->email, '', true);
186 186
         }
187 187
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             'confirmed' => $skipConfirmEmail
207 207
         ]);
208 208
 
209
-        if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
209
+        if ( ! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
210 210
             $this->sendConfirmationEmail($user->email);
211 211
         }
212 212
 
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function sendReset($email)
249 249
     {
250
-        if (! $user = $this->repo->first(['email' => $email])) {
250
+        if ( ! $user = $this->repo->first(['email' => $email])) {
251 251
             \Errors::notFound('email');
252 252
         }
253 253
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
             'password'              => $password,
272 272
             'password_confirmation' => $passwordConfirmation,
273 273
             'token'                 => $token
274
-        ], function ($user, $password) {
274
+        ], function($user, $password) {
275 275
             $this->repo->save(['id' => $user->id, 'password' => $password]);
276 276
         });
277 277
 
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
     public function changePassword($password, $oldPassword)
305 305
     {
306 306
         $user = \Auth::user();
307
-        if (! \Hash::check($oldPassword, $user->password)) {
307
+        if ( ! \Hash::check($oldPassword, $user->password)) {
308 308
             \Errors::invalidOldPassword();
309 309
         }
310 310
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      */
320 320
     public function confirmEmail($confirmationCode)
321 321
     {
322
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
322
+        if ( ! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
323 323
             \Errors::invalidConfirmationCode();
324 324
         }
325 325
 
Please login to merge, or discard this patch.