1196281550 2017-12-12 19:45:26 4277次浏览 8条评论 1 2 3
<?php

namespace backend\controllers;
use Yii;
use yii\web\Controller;

class ZiceController extends Controller
{
    public $enableCsrfValidation = false;//取消crsf攻击
    public $layout = false;//关闭布局
    //首页
    public function actionIndex()
    {
        return $this->render('index');
    }
    //注册
    public function actionRegister()
    {
        $post = $_POST;
        if($post)
        {
            $res = \Yii::$app->db->createCommand()->insert('user',$post)->execute();
            if($res){
               echo "<script>alert('注册成功,正在前往登录页面');location.href='?r=zice/login'</script>";
            }
            else{
                echo "<script>alert('注册失败,请重新填写');location.href='?r=zice/register'</script>";
            }
        }
        else
        {

            return $this->render('register');
        }
    }
    //登录
    public function actionLogin()
    {
        $post = isset($_POST)?$_POST:'';

        if($post){
            $res = \Yii::$app->db->createCommand("SELECT * FROM user WHERE phone='".$post['phone']."' and pwd = '".$post['pwd']."'")->queryOne();
           if($res['phone'] == $post['phone']){
                if ($res['pwd'] == $post['pwd']){
                    echo "<script>alert('登录成功,正在跳转');location.href='?r=zice/index'</script>";
                }
                else{
                    echo "<script>alert('登录失败,账号或密码错误');location.href='?r=zice/login'</script>";
                }
           }
           else{
               echo "<script>alert('登录失败,用户名有误');location.href='?r=zice/login'</script>";
           }
        }
        else{

            return $this->render('login');
        }
    }
}
觉得很赞
您需要登录后才可以评论。登录 | 立即注册