Login.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. *
  4. * User: anyluck
  5. * Date: 2020/6/3
  6. * Time: 9:46
  7. */
  8. namespace app\web\controller;
  9. use app\common\controller\Upfile;
  10. use app\common\model\PhoneCode;
  11. use app\common\model\System;
  12. use app\common\model\User;
  13. use app\web\model\Mail;
  14. use app\web\model\Send;
  15. use app\web\model\Team;
  16. use app\web\model\Tripartite;
  17. use Ramsey\Uuid\Uuid;
  18. class Login
  19. {
  20. // todo 登录注册
  21. // 登录
  22. public function in_login()
  23. {
  24. $phone = input("phone");
  25. if (!$phone) json_result(400, "请输入手机号码或者邮箱账号");
  26. $pwd = input("pwd");
  27. if (!$pwd) json_result(400, "请输入登录密码");
  28. $where["phone|mail"] = $phone;
  29. $user = User::where($where)->find();
  30. if (!$user) {
  31. json_result(400, "账号不存在");
  32. }
  33. if (!password_verify($pwd, $user->pwd)) {
  34. json_result(400, "密码错误");
  35. }
  36. if ($user->status == 1) {// 禁止登录
  37. if ($user->status_time > time()) {
  38. json_result(400, "该账号已经封号");
  39. } else {// 解除禁止登陸
  40. User::update(["status" => 0, "status_time" => ""], ["id" => $user->id]);
  41. }
  42. }
  43. // 给账号加活跃度
  44. $update["update_time"]=time();
  45. User::update($update,["id"=>$user->id]);
  46. json_result(200, "登录成功", $user);
  47. }
  48. // 获取验证码
  49. public function code()
  50. {
  51. $phone = input("phone");
  52. if (!$phone) json_result(400, "请输入手机号或者邮箱");
  53. $type = input("type") ?: 0;
  54. // 查询是否重复发送
  55. $where["phone"] = $phone;
  56. $where["add_time"] = ["<", time() - (1 * 60)];
  57. $phone_code = PhoneCode::where($where)->find();
  58. if ($phone_code) {
  59. json_result(400, "验证码已发送请稍后再发送");
  60. }
  61. $res = Tripartite::send_code($phone, $type);
  62. json_result(200, "验证码发送成功");
  63. }
  64. // 注册
  65. public function register()
  66. {
  67. $phone = input("phone");
  68. if (!$phone) json_result(400, "请输入手机号或者邮箱");
  69. $code = input("code");
  70. if (!$code) json_result(400, "请输入验证码");
  71. $name = input("name");
  72. if (!$name) json_result(400, "请输入账户呢称");
  73. $type = input("type") ?: 0;
  74. $pwd = input("pwd");
  75. if (!$pwd) json_result(400, "请输入密码");
  76. $pid = input("pid");
  77. // 查看账号是存在
  78. $where["phone|mail"] = $phone;
  79. $user = User::where($where)->find();
  80. if ($user) {
  81. json_result(400, "账号已注册,请前去登录");
  82. }
  83. // 验证码
  84. $phone_code = Tripartite::push_code($phone);
  85. if ($phone_code != $code) {
  86. json_result(400, "验证码错误");
  87. }
  88. if ($pid) {
  89. $wheres["code"] = $pid;
  90. $pid_user = User::where($wheres)->find();
  91. if (!$pid_user) {
  92. json_result(400, "上级账号不存在");
  93. }
  94. $add["pid"] = $pid_user->id;
  95. // Team::all_tem($pid_user->id);
  96. }
  97. $add["code"] = uniqid();
  98. if ($type == 0) {
  99. $add["phone"] = $phone;
  100. } else {
  101. $add["mail"] = $phone;
  102. }
  103. $add["name"] = $name;
  104. $add["uuid"] = uniqid();// 收款ID
  105. $uuid = Uuid::uuid1();
  106. $add["token"] = $uuid->getHex();;
  107. $add["add_time"] = time();
  108. $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  109. // dump($add);die();
  110. User::create($add);
  111. json_result(200, "注册成功");
  112. }
  113. // 忘记密码 第一部
  114. public function forget_password()
  115. {
  116. $phone = input("phone");
  117. if (!$phone) json_result(400, "请输入手机号码或者邮箱");
  118. $type = input("type") ?: 0;
  119. $code = input("code");
  120. if (!$code) json_result(400, "请输入验证码");
  121. $name = input("name");
  122. // 查看账号是存在
  123. $where["phone|mail"] = $phone;
  124. $user = User::where($where)->find();
  125. if (!$user) {
  126. json_result(400, "账号不存在");
  127. }
  128. // 验证码
  129. $phone_code = Tripartite::push_code($phone, $type);
  130. if ($phone_code != $code) {
  131. json_result(400, "验证码错误");
  132. }
  133. json_result(200, "验证码成功");
  134. }
  135. // 修改密码--第二步
  136. public function update_password()
  137. {
  138. $pwd = input("pwd");
  139. if (!$pwd) json_result(400, "请输入密码");
  140. $phone = input("phone");
  141. if (!$phone) json_result(400, "请输入手机号码或者邮箱");
  142. // 查看账号是存在
  143. $where["phone|mail"] = $phone;
  144. $user = User::where($where)->find();
  145. if (!$user) {
  146. json_result(400, "账号不存在");
  147. }
  148. $add["pwd"] = password_hash($pwd, PASSWORD_DEFAULT);;
  149. User::where(["id" => $user->id])->update($add);
  150. json_result(200, "设置密码成功");
  151. }
  152. // 上传图片
  153. public function up_image()
  154. {
  155. $upfile = new Upfile();
  156. $ret = $upfile->Uploads();
  157. json_result(200, "", $ret["url"]);
  158. }
  159. // 会员协议
  160. public function Membership()
  161. {
  162. $where["name"]="Membership";
  163. $data=System::where($where)->field("value")->find();
  164. json_result(200,"",$data->value?:"");
  165. }
  166. // 测试接口
  167. public function test()
  168. {
  169. // $eaml="www.794230322@outlook.com";
  170. // $eaml="3398530177@qq.com";
  171. // $data["user_email"]=$eaml;
  172. // $data["name"]=$eaml;
  173. // $data["content"]="【BTS】您的验证码是123456";
  174. // Mail::sendEmail($data);
  175. }
  176. }