Is there a way to filter email adresses?

Aidan Gerbil Posted in Component Development 3 years ago

Hello! I am setting up OSSN for my business. All of my employees have an email address that ends in my domain name I wanted to know if there was a way to make it so only people with that address can make accounts?

Replies
us Aidan Gerbil Replied 3 years ago

Thank you for the help! I will try this tomorrow. I am used to working with java so I am not to good with PhP. If I can’t get it to work I’ll email you though!

Indonesian Arsalan Shah Replied 3 years ago

Dear Adian, you need to consult the developer for that. It requires good knowledge in programming to handle the case. The developer need to check the

  1. $email domain contains your domain then allow the reg
  2. Otherwise don't allow it.
  3. Email can be obtained in same function by $email = input('email'); and then the rest condition need to be written.

In the end it should appear like this

function restrict_usernames($name, $type, $params) {
        if($params['action'] == 'user/register') {
                $email = input('email');
                if($email does not contain your domain then do not allow it) {
                //if(!str_ends_with('@yourdomain.com', $email){
                                header('Content-Type: application/json');
                                echo json_encode(array(
                                        'dataerr' => ossn_print('restrictusername:error'),
                                ));
                                exit();
                }
        }
}

You may contact me at [email protected] for custom work at additional cost.

us Aidan Gerbil Replied 3 years ago

I now have `function restrict_usernames($name, $type, $params) {
if($params['action'] == 'user/register') {
$username = strtolower(input('username'));

            $component = new OssnComponents();
            $list      = $component->getSettings('RestrictUsernames');
            if($list && isset($list->list) && !empty($list->list)) {
                    $usernames = explode(PHP_EOL, $list->list);
                    $usernames = array_map('strtolower', $usernames);
                    $usernames = array_map('trim', $usernames);
                    $email = input('email');
                            header('Content-Type: application/json');
                            echo json_encode(array(
                                    'dataerr' => ossn_print('restrictusername:error'),
                            ));
                            exit();
                    }
            }
    }`

Will it only restrict the end of the email like @email.com?

us Aidan Gerbil Replied 3 years ago

Like this? if(in_array($email = input('email');)) {

Indonesian Arsalan Shah Replied 3 years ago