Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Nologin authentication login - prevents user login.
19
 *
20
 * @package auth_nologin
21
 * @author Petr Skoda
22
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->libdir.'/authlib.php');
28
 
29
/**
30
 * Plugin for no authentication - disabled user.
31
 */
32
class auth_plugin_nologin extends auth_plugin_base {
33
 
34
 
35
    /**
36
     * Constructor.
37
     */
38
    public function __construct() {
39
        $this->authtype = 'nologin';
40
    }
41
 
42
    /**
43
     * Old syntax of class constructor. Deprecated in PHP7.
44
     *
45
     * @deprecated since Moodle 3.1
46
     */
47
    public function auth_plugin_nologin() {
48
        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
49
        self::__construct();
50
    }
51
 
52
    /**
53
     * Do not allow any login.
54
     *
55
     */
56
    function user_login($username, $password) {
57
        return false;
58
    }
59
 
60
    /**
61
     * No password updates.
62
     */
63
    function user_update_password($user, $newpassword) {
64
        return false;
65
    }
66
 
67
    function prevent_local_passwords() {
68
        // just in case, we do not want to loose the passwords
69
        return false;
70
    }
71
 
72
    /**
73
     * No external data sync.
74
     *
75
     * @return bool
76
     */
77
    function is_internal() {
78
        //we do not know if it was internal or external originally
79
        return true;
80
    }
81
 
82
    /**
83
     * No changing of password.
84
     *
85
     * @return bool
86
     */
87
    function can_change_password() {
88
        return false;
89
    }
90
 
91
    /**
92
     * No password resetting.
93
     */
94
    function can_reset_password() {
95
        return false;
96
    }
97
 
98
    /**
99
     * Returns true if plugin can be manually set.
100
     *
101
     * @return bool
102
     */
103
    function can_be_manually_set() {
104
        return true;
105
    }
106
 
107
    /**
108
     * Returns information on how the specified user can change their password.
109
     * User accounts with authentication type set to nologin are disabled accounts.
110
     * They cannot change their password.
111
     *
112
     * @param stdClass $user A user object
113
     * @return string[] An array of strings with keys subject and message
114
     */
115
    public function get_password_change_info(stdClass $user): array {
116
        $site = get_site();
117
 
118
        $data = new stdClass();
119
        $data->firstname = $user->firstname;
120
        $data->lastname  = $user->lastname;
121
        $data->username  = $user->username;
122
        $data->sitename  = format_string($site->fullname);
123
        $data->admin     = generate_email_signoff();
124
 
125
        $message = get_string('emailpasswordchangeinfodisabled', '', $data);
126
        $subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname));
127
 
128
        return [
129
            'subject' => $subject,
130
            'message' => $message
131
        ];
132
    }
133
}
134
 
135