cakephp的电话号码验证 [英] cakephp phone number validation

查看:251
本文介绍了cakephp的电话号码验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的cakephp 2.x所以我不知道如何做这个..我想从他的电子邮件地址和电话号码登录用户。我的意图是如果数据库中的数字是这个12345并且用户尝试通过这个号码+12345登录他可以登录到系统..我已经写了一个代码,但我不知道如何使用这个或调整我的代码在auth组件作为auth组件

这里是我的控制器

  public function beforeFilter(){
parent :: beforeFilter();


$ this-> Auth-> authenticate = array(
'Authenticate.Cookie'=> array(
'fields'=> array (
'username'=>'email',
'password'=>'password'
),
'userModel'=>'User',
'scope'=> array('User.active'=> 1)
),
'Authenticate.MultiColumn'=> array(
'fields'=&数组(
'username'=>'email',
'password'=>'password'
),
'columns'=& ,'mobileNo'),
'userModel'=>'User',

);
}




public function login(){


if($ this-> Auth-> login()|| $ this-> Auth-> loggedIn()){
$ this-> redirect('/ users / dashboard');
} else {
$ this-> layout ='logindefault';
$ this-> set('title_for_layout','Account Login');
/ * $ this-> Auth-> logout();
$ cookie = $ this-> Cookie-> read('Auth.User'); * /


if($ this-> request-> is('post')){



b $ b if($ this-> Auth-> login()|| $ this-> Auth-> loggedIn()){
if($ this-> Session-& 'Auth.User')){


$ this-> _setCookie($ this-> Auth-> user('idUser'))
$ this-> redirect('/ users / dashboard');

}} else {
$ this-> Session-> setFlash('Incorrect Email / Password Combination');
}
}}
}

我正试图添加..

  $ mobileNo ='+ 123456789'; 
if(strpos($ mobileNo,'+')!== false){
$ mobileNo = str_replace(+,,$ mobileNo);
}

?>

解决方案

我已经这样做,它的工作



我添加这一行就在$ this-> Auth-> login
$ this-> request-> data ['User'] ['email'] = $ mobileNo;



source:用户登录Cakephp时的字符串连接


i am new to cakephp 2.x so i dont know how to do this .. i want to login the user from his email address and phone number..what my intention is if the number in database is this "12345" and the user is trying to login through this number "+12345" he can be login into the system.. i have written a code but i dont know how can i use this or to adjust my code within the auth component as the auth component is autometically logging the user ..

here is my controller

 public function beforeFilter() {
    parent::beforeFilter();


    $this->Auth->authenticate = array(
        'Authenticate.Cookie' => array(
            'fields' => array(
                'username' => 'email',
                'password' => 'password'
            ),
            'userModel' => 'User',
            'scope' => array('User.active' => 1)
        ),
        'Authenticate.MultiColumn' => array(
            'fields' => array(
                'username' => 'email',
                'password' => 'password'
            ),
            'columns' => array('email', 'mobileNo'),
            'userModel' => 'User',
        )
    );
 }




public function login() {


    if ($this->Auth->login() || $this->Auth->loggedIn()) {
        $this->redirect('/users/dashboard');
    }else{
    $this->layout='logindefault';
    $this->set('title_for_layout', 'Account Login');
    /*$this->Auth->logout();
     $cookie = $this->Cookie->read('Auth.User'); */


    if ($this->request->is('post')) {




        if ($this->Auth->login() || $this->Auth->loggedIn()) {
            if ($this->Session->check('Auth.User')){


            $this->_setCookie($this->Auth->user('idUser'));
            $this->redirect('/users/dashboard');

        } }else {
            $this->Session->setFlash('Incorrect Email/Password Combination');
        }
    }}
}

here is the code which i am trying to add ..

    $mobileNo='+123456789';
   if (strpos($mobileNo,'+') !== false) {
      $mobileNo=str_replace("+", "",$mobileNo);
   }

?>

解决方案

i have done this and it works

i add this line just before the $this->Auth->login() $this->request->data['User']['email'] = $mobileNo;

source:string concatenation when user log in Cakephp

这篇关于cakephp的电话号码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆