审查视图

application/api/controller/Validate.php 3.6 KB
景龙 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\User;

/**
 * 验证接口
 */
class Validate extends Api
{

    protected $noNeedLogin = '*';
    protected $layout = '';
    protected $error = null;

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 检测邮箱
     * 
     * @param string $email 邮箱
     * @param string $id 排除会员ID
     */
    public function check_email_available()
    {
        $email = $this->request->request('email');
        $id = (int) $this->request->request('id');
        $count = User::where('email', '=', $email)->where('id', '<>', $id)->count();
        if ($count > 0)
        {
            $this->error(__('邮箱已经被占用'));
        }
        $this->success();
    }

    /**
     * 检测用户名
     * 
     * @param string $username 用户名
     * @param string $id 排除会员ID
     */
    public function check_username_available()
    {
        $email = $this->request->request('username');
        $id = (int) $this->request->request('id');
        $count = User::where('username', '=', $email)->where('id', '<>', $id)->count();
        if ($count > 0)
        {
            $this->error(__('用户名已经被占用'));
        }
        $this->success();
    }

    /**
     * 检测手机
     * 
     * @param string $mobile 手机号
     * @param string $id 排除会员ID
     */
    public function check_mobile_available()
    {
        $mobile = $this->request->request('mobile');
        $id = (int) $this->request->request('id');
        $count = User::where('mobile', '=', $mobile)->where('id', '<>', $id)->count();
        if ($count > 0)
        {
            $this->error(__('该手机号已经占用'));
        }
        $this->success();
    }

    /**
     * 检测手机
     * 
     * @param string $mobile 手机号
     */
    public function check_mobile_exist()
    {
        $mobile = $this->request->request('mobile');
        $count = User::where('mobile', '=', $mobile)->count();
        if (!$count)
        {
            $this->error(__('手机号不存在'));
        }
        $this->success();
    }

    /**
     * 检测邮箱
     * 
     * @param string $mobile 邮箱
     */
    public function check_email_exist()
    {
        $email = $this->request->request('email');
        $count = User::where('email', '=', $email)->count();
        if (!$count)
        {
            $this->error(__('邮箱不存在'));
        }
        $this->success();
    }

    /**
     * 检测手机验证码
     * 
     * @param string $mobile    手机号
     * @param string $captcha   验证码
     * @param string $event     事件
     */
    public function check_sms_correct()
    {
        $mobile = $this->request->request('mobile');
        $captcha = $this->request->request('captcha');
        $event = $this->request->request('event');
        if (!\app\common\library\Sms::check($mobile, $captcha, $event))
        {
            $this->error(__('验证码不正确'));
        }
        $this->success();
    }

    /**
     * 检测邮箱验证码
     * 
     * @param string $email     邮箱
     * @param string $captcha   验证码
     * @param string $event     事件
     */
    public function check_ems_correct()
    {
        $email = $this->request->request('email');
        $captcha = $this->request->request('captcha');
        $event = $this->request->request('event');
        if (!\app\common\library\Ems::check($email, $captcha, $event))
        {
            $this->error(__('验证码不正确'));
        }
        $this->success();
    }

}