1: <?php
2: /*
3: * SimpleID
4: *
5: * Copyright (C) Kelvin Mo 2021-2026
6: *
7: * This program is free software; you can redistribute it and/or
8: * modify it under the terms of the GNU General Public
9: * License as published by the Free Software Foundation; either
10: * version 2 of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program; if not, write to the Free
19: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20: *
21: */
22:
23: namespace SimpleID\Auth;
24:
25: use SimpleID\Models\User;
26: use SimpleID\Util\Forms\FormSubmitEvent;
27:
28: /**
29: * An event used to process the login form.
30: *
31: */
32: class LoginFormSubmitEvent extends FormSubmitEvent implements AuthResultInterface {
33: use AuthResultTrait;
34:
35: /**
36: * Creates a form submission event
37: *
38: * @param \SimpleID\Util\Forms\FormState $form_state a reference to the form state array
39: * @param string $eventName the name of the event, or the name
40: */
41: public function __construct($form_state, $eventName = null) {
42: parent::__construct($form_state, $eventName);
43:
44: if (isset($form_state['auth_level'])) $this->auth_level = $form_state['auth_level'];
45: }
46:
47: /**
48: * {@inheritdoc}
49: */
50: public function isAuthSuccessful() {
51: if ($this->user != null) return true;
52:
53: if (isset($this->form_state['mode']) && ($this->auth_level >= $this->form_state['mode'])) return true;
54: return false;
55: }
56:
57: /**
58: * Set the user object for the user that has been automatically
59: * authenticated.
60: *
61: * @param \SimpleID\Models\User $user the user
62: * @return void
63: */
64: public function setUser(User $user) {
65: $this->user = $user;
66: }
67:
68: /**
69: * Sets the authentication level.
70: *
71: * If the authentication level specified in the parameter is less
72: * than the level set by previous listeners to this event, it
73: * is ignored.
74: *
75: * @param int $auth_level the authentication level
76: * @return void
77: */
78: public function setAuthLevel($auth_level) {
79: $this->auth_level = max($auth_level, $this->auth_level);
80: }
81:
82: /**
83: * Adds the name of the module that authenticated the user
84: *
85: * @param string $auth_module_name the name of the module that
86: * authenticated the user
87: * @return void
88: */
89: public function addAuthModuleName($auth_module_name) {
90: $this->auth_module_names[] = $auth_module_name;
91: }
92: }
93:
94: ?>