123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- <?php
- namespace app\web\controller;
- use app\common\controller\Upfile;
- use app\common\model\PhoneCode;
- use app\common\model\System;
- use app\common\model\User;
- use app\web\model\Mail;
- use app\web\model\Orders;
- use app\web\model\Send;
- use app\web\model\Team;
- use app\web\model\Tripartite;
- use Ramsey\Uuid\Uuid;
- class Login
- {
-
-
- public function in_login()
- {
- $phone = trim(input("phone"));
- if (!$phone) json_result(400, "请输入账号");
- $pwd = trim(input("pwd"));
- if (!$pwd) json_result(400, "请输入登录密码");
- $where["name"] = $phone;
- $user = User::where($where)->find();
- if (!$user) {
- json_result(400, "账号不存在");
- }
- if (!password_verify($pwd, $user->pwd)) {
- json_result(400, "密码错误");
- }
- if ($user->status == 1) {
- if ($user->status_time > time()) {
- json_result(400, "该账号已经封号");
- } else {
- User::update(["status" => 0, "status_time" => ""], ["id" => $user->id]);
- }
- }
-
- $update["update_time"]=time();
- User::update($update,["id"=>$user->id]);
- json_result(200, "登录成功", $user);
- }
-
- public function code()
- {
- $phone = trim(input("phone"));
- if (!$phone) json_result(400, "请输入手机号或者邮箱");
- $type = input("type") ?: 0;
-
- $where["phone"] = $phone;
- $where["add_time"] = ["<", time() - (1 * 60)];
- $phone_code = PhoneCode::where($where)->find();
- if ($phone_code) {
- json_result(400, "验证码已发送请稍后再发送");
- }
- $res = Tripartite::send_code($phone, $type);
- json_result(200, "验证码发送成功");
- }
-
- public function register()
- {
- $phone = trim(input("phone"));
- if (!$phone) json_result(400, "请输入手机号或者邮箱");
- $code = trim(input("code"));
- if (!$code) json_result(400, "请输入验证码");
- $name = trim(input("name"));
- if (!$name) json_result(400, "请输入账户");
- $type = input("type") ?: 0;
- $pwd = trim(input("pwd"));
- if (!$pwd) json_result(400, "请输入密码");
- $pid = trim(input("pid"));
-
- $user_data= User::where(["name"=>$name])->find();
- if ($user_data){
- json_result(400,"账号已存在,请重新选一个名字吧");
- }
- $where["phone|mail"] = $phone;
- $user = User::where($where)->count();
- $phone_email= Orders::phone_email();
- if ($user>=$phone_email) {
- json_result(400, "账号手机号或邮箱已经注册超过".$phone_email);
- }
-
- $phone_code = Tripartite::push_code($phone);
- if ($phone_code != $code) {
- json_result(400, "验证码错误");
- }
- if ($pid) {
- $wheres["code"] = $pid;
- $pid_user = User::where($wheres)->find();
- if (!$pid_user) {
- json_result(400, "上级账号不存在");
- }
- $add["pid"] = $pid_user->id;
- }
- $add["code"] = uniqid();
- if ($type == 0) {
- $add["phone"] = $phone;
- } else {
- $add["mail"] = $phone;
- }
- $add["name"] = $name;
- $add["uuid"] = uniqid();
- $uuid = Uuid::uuid1();
- $add["token"] = $uuid->getHex();;
- $add["add_time"] = time();
- $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
- User::create($add);
- json_result(200, "注册成功");
- }
-
- public function forget_password()
- {
- $phone = trim(input("phone"));
- if (!$phone) json_result(400, "请输入手机号码或者邮箱");
- $type = input("type") ?: 0;
- $code = trim(input("code"));
- if (!$code) json_result(400, "请输入验证码");
- $name = trim(input("name"));
-
- $where["name"] = $name;
- $user = User::where($where)->find();
- if (!$user) {
- json_result(400, "账号不存在");
- }
-
- $phone_code = Tripartite::push_code($phone, $type);
- if ($phone_code != $code) {
- json_result(400, "验证码错误");
- }
- json_result(200, "验证码成功");
- }
-
- public function update_password()
- {
- $pwd = trim(input("pwd"));
- if (!$pwd) json_result(400, "请输入密码");
- $phone = trim(input("phone"));
- if (!$phone) json_result(400, "请输入手机号码或者邮箱");
-
- $where["phone|mail"] = $phone;
- $user = User::where($where)->find();
- if (!$user) {
- json_result(400, "账号不存在");
- }
- $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
- User::where(["id" => $user->id])->update($add);
- json_result(200, "设置密码成功");
- }
-
- public function up_image()
- {
- \app\web\model\Upfile::Uploadss();
- }
-
- public function Membership()
- {
- $where["name"]="Membership";
- $data=System::where($where)->field("value")->find();
- json_result(200,"",$data->value?:"");
- }
-
- public function test()
- {
- }
- }
|