Topic on Project:Support desk/Flow

Force email domain for new users

14
GreatOom (talkcontribs)

Hi all!

I'd like to restrict the Wiki users to a specific email domain. They should just use their EDU account. I did some search but I found only some outdated results, e.g. using "$wgEmailDomain".

Is there some documentation how it works in current MediaWiki release?

Also I'd like to force a specific user name based on the email address.

So the email address is something like "FirstName.LastName@domain.com" and I want a username "FirstNameLastName". Any clues how to force this?

Thanks in advance for your help.

Bawolff (talkcontribs)

i guess AuthManager can do this. the docs are a bit "dense" though.

GreatOom (talkcontribs)

Thanks for your reply. I looked the at theAuthManager pages but it does not help me because I'm a newbie here and I have no idea how to realize this using that extension.

I assume that there are many others with similar needs since there are many outdated posts about such a request. I need a simple example…

Jonathan3 (talkcontribs)
GreatOom (talkcontribs)

… and manually confirm/deny potential users.

This is no solution for me since there may many new users for a lecture while I'm not in the office. It must be handled without any interaction from an admin.

GreatOom (talkcontribs)

I found ApiValidateSignup.php (SignupAPI). Is it possible to add a hook for this API where I can make my own checks?

Jonathan3 (talkcontribs)

The AuthManager stuff is impossible to understand. What about just letting anyone create an account but use Manual:Hooks/UserLoggedIn and the User object from that to getEmail, check it, then if you don't like it doLogout? Probably too late by then to have any impact on the username.

Bawolff (talkcontribs)
GreatOom (talkcontribs)

This looks good. I check now the documentation about Hooks to get a clue how to use it. Manual:Hooks is not really helpful for me. Now I look for samples.

I will post my solution when I got it working.

Bawolff (talkcontribs)

something like

$wgHooks["isValidEmailAddr"][] = function($email, &$result) {
  if (substr($email, -4) !== '.edu' ) {
    $result = false;
    return false;
  }
};

Totally untested, i prob made a mistake.

GreatOom (talkcontribs)

Many thanks Bawolff!

It works great. I modified your code so that it is easier to use:

$wgHooks["isValidEmailAddr"][] = function($email) {

$mailDomain = 'myDomain.edu';

  return (substr($email, -strlen($mailDomain)) == $mailDomain );

};

Bawolff (talkcontribs)

note, its the $result parameter that matters the most. Returning false means dont do other validation checks and use the value of $result instead.

GreatOom (talkcontribs)

Thanks for your help.

I modified the code so that "$result" is assigned, too.

$wgHooks["isValidEmailAddr"][] = function($email, &$result) {

$mailDomain = 'myDomain.edu';

$result=(substr($email, -strlen($mailDomain)) == $mailDomain );

return $result;

};

Cfoh (talkcontribs)

Wow, this is the solution I was looking for


What if I want to allow multiple domains?