Completed
Push — master ( bb8c97...03c924 )
by Vojta
01:50
created
components/CodeLogin.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -16,123 +16,123 @@
 block discarded – undo
16 16
 
17 17
 class CodeLogin extends ComponentBase
18 18
 {
19
-    public function componentDetails()
20
-    {
21
-        return [
22
-            'name'        => 'vojtasvoboda.codelogin::lang.logincomponent.name',
23
-            'description' => 'vojtasvoboda.codelogin::lang.logincomponent.description'
24
-        ];
25
-    }
26
-
27
-    public function defineProperties()
28
-    {
29
-        return [
30
-            'redirect' => [
31
-                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.title',
32
-                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.description',
33
-                'type'        => 'dropdown',
34
-                'default'     => ''
35
-            ],
36
-            'visible' => [
37
-                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.visible.title',
38
-                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.visible.description',
39
-                'type'        => 'checkbox',
40
-                'default'     => false
41
-            ],
42
-            'button' => [
43
-                'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.button.title',
44
-                'description' => 'vojtasvoboda.codelogin::lang.logincomponent.button.description',
45
-                'type'        => 'string',
46
-                'default'     => 'enter'
47
-            ]
48
-        ];
49
-    }
50
-
51
-    public function getRedirectOptions()
52
-    {
53
-        $default = [
54
-            '' => '- none -'
55
-        ];
56
-        $pages = Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');
57
-
58
-        return $default + $pages;
59
-    }
60
-
61
-    /**
62
-     * Executed when this component is bound to a page or layout.
63
-     */
64
-    public function onRun()
65
-    {
66
-        $this->page['visible'] = $this->property('visible');
67
-        $this->page['button'] = $this->property('button');
68
-    }
69
-
70
-    /**
71
-     * Sign in the user
72
-     */
73
-    public function onCodesignin()
74
-    {
75
-        try {
76
-            return $this->doSignin();
77
-
78
-        } catch (Exception $ex) {
79
-            if (Request::ajax()) {
80
-                throw $ex;
81
-            }
82
-            Flash::error($ex->getMessage());
83
-        }
84
-    }
85
-
86
-    private function doSignin()
87
-    {
88
-        /*
19
+	public function componentDetails()
20
+	{
21
+		return [
22
+			'name'        => 'vojtasvoboda.codelogin::lang.logincomponent.name',
23
+			'description' => 'vojtasvoboda.codelogin::lang.logincomponent.description'
24
+		];
25
+	}
26
+
27
+	public function defineProperties()
28
+	{
29
+		return [
30
+			'redirect' => [
31
+				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.title',
32
+				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.redirect.description',
33
+				'type'        => 'dropdown',
34
+				'default'     => ''
35
+			],
36
+			'visible' => [
37
+				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.visible.title',
38
+				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.visible.description',
39
+				'type'        => 'checkbox',
40
+				'default'     => false
41
+			],
42
+			'button' => [
43
+				'title'       => 'vojtasvoboda.codelogin::lang.logincomponent.button.title',
44
+				'description' => 'vojtasvoboda.codelogin::lang.logincomponent.button.description',
45
+				'type'        => 'string',
46
+				'default'     => 'enter'
47
+			]
48
+		];
49
+	}
50
+
51
+	public function getRedirectOptions()
52
+	{
53
+		$default = [
54
+			'' => '- none -'
55
+		];
56
+		$pages = Page::sortBy('baseFileName')->lists('baseFileName', 'baseFileName');
57
+
58
+		return $default + $pages;
59
+	}
60
+
61
+	/**
62
+	 * Executed when this component is bound to a page or layout.
63
+	 */
64
+	public function onRun()
65
+	{
66
+		$this->page['visible'] = $this->property('visible');
67
+		$this->page['button'] = $this->property('button');
68
+	}
69
+
70
+	/**
71
+	 * Sign in the user
72
+	 */
73
+	public function onCodesignin()
74
+	{
75
+		try {
76
+			return $this->doSignin();
77
+
78
+		} catch (Exception $ex) {
79
+			if (Request::ajax()) {
80
+				throw $ex;
81
+			}
82
+			Flash::error($ex->getMessage());
83
+		}
84
+	}
85
+
86
+	private function doSignin()
87
+	{
88
+		/*
89 89
          * Validate input
90 90
          */
91
-        $data = post();
91
+		$data = post();
92 92
 
93
-        $rules = [];
94
-        $rules['code'] = 'required|min:2';
93
+		$rules = [];
94
+		$rules['code'] = 'required|min:2';
95 95
 
96
-        $messages = [];
97
-        $messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required');
96
+		$messages = [];
97
+		$messages['required'] = trans('vojtasvoboda.codelogin::lang.form.required');
98 98
 
99
-        $validation = Validator::make($data, $rules, $messages);
100
-        if ($validation->fails()) {
101
-            throw new ValidationException($validation);
102
-        }
99
+		$validation = Validator::make($data, $rules, $messages);
100
+		if ($validation->fails()) {
101
+			throw new ValidationException($validation);
102
+		}
103 103
 
104
-        /*
104
+		/*
105 105
          * Find user by password
106 106
          */
107
-        $users = new UserRepository();
108
-        $userToLog = $users->getUserByPassword(array_get($data, 'code'));
109
-        if ($userToLog === null) {
110
-            $exception = new ValidationException([trans('vojtasvoboda.codelogin::lang.form.wrong_code')]);
111
-            throw $exception;
112
-        }
113
-
114
-        /*
107
+		$users = new UserRepository();
108
+		$userToLog = $users->getUserByPassword(array_get($data, 'code'));
109
+		if ($userToLog === null) {
110
+			$exception = new ValidationException([trans('vojtasvoboda.codelogin::lang.form.wrong_code')]);
111
+			throw $exception;
112
+		}
113
+
114
+		/*
115 115
          * Authenticate user
116 116
          */
117
-        $remember = true;
118
-        $user = Auth::authenticate([
119
-            'login' => $userToLog->email,
120
-            'password' => array_get($data, 'code')
121
-        ], $remember);
117
+		$remember = true;
118
+		$user = Auth::authenticate([
119
+			'login' => $userToLog->email,
120
+			'password' => array_get($data, 'code')
121
+		], $remember);
122 122
 
123
-        /*
123
+		/*
124 124
          * Event just for backward compatibility. It's more then recommand use
125 125
          * standard rainlab.user.login event - see readme.
126 126
          */
127
-        Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]);
127
+		Event::fire('vojtasvoboda.codelogin.afterlogin', [$user]);
128 128
 
129
-        /*
129
+		/*
130 130
          * Redirect to the intended page after successful sign in
131 131
          */
132
-        $redirectUrl = $this->pageUrl($this->property('redirect'));
132
+		$redirectUrl = $this->pageUrl($this->property('redirect'));
133 133
 
134
-        if ($redirectUrl = post('redirect', $redirectUrl)) {
135
-            return Redirect::intended($redirectUrl);
136
-        }
137
-    }
134
+		if ($redirectUrl = post('redirect', $redirectUrl)) {
135
+			return Redirect::intended($redirectUrl);
136
+		}
137
+	}
138 138
 }
Please login to merge, or discard this patch.