Merge branch 'MDL-70537-master' of https://github.com/sammarshallou/moodle
[moodle.git] / auth / nologin / auth.php
blob7b7dd3a0128d2eb7d4cd590dffea8b6c8db1eb88
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.
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/>.
17 /**
18 * Nologin authentication login - prevents user login.
20 * @package auth_nologin
21 * @author Petr Skoda
22 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
25 defined('MOODLE_INTERNAL') || die();
27 require_once($CFG->libdir.'/authlib.php');
29 /**
30 * Plugin for no authentication - disabled user.
32 class auth_plugin_nologin extends auth_plugin_base {
35 /**
36 * Constructor.
38 public function __construct() {
39 $this->authtype = 'nologin';
42 /**
43 * Old syntax of class constructor. Deprecated in PHP7.
45 * @deprecated since Moodle 3.1
47 public function auth_plugin_nologin() {
48 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
49 self::__construct();
52 /**
53 * Do not allow any login.
56 function user_login($username, $password) {
57 return false;
60 /**
61 * No password updates.
63 function user_update_password($user, $newpassword) {
64 return false;
67 function prevent_local_passwords() {
68 // just in case, we do not want to loose the passwords
69 return false;
72 /**
73 * No external data sync.
75 * @return bool
77 function is_internal() {
78 //we do not know if it was internal or external originally
79 return true;
82 /**
83 * No changing of password.
85 * @return bool
87 function can_change_password() {
88 return false;
91 /**
92 * No password resetting.
94 function can_reset_password() {
95 return false;
98 /**
99 * Returns true if plugin can be manually set.
101 * @return bool
103 function can_be_manually_set() {
104 return true;
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.
112 * @param stdClass $user A user object
113 * @return string[] An array of strings with keys subject and message
115 public function get_password_change_info(stdClass $user) : array {
116 $site = get_site();
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();
125 $message = get_string('emailpasswordchangeinfodisabled', '', $data);
126 $subject = get_string('emailpasswordchangeinfosubject', '', format_string($site->fullname));
128 return [
129 'subject' => $subject,
130 'message' => $message