AuthService.php 688 B

12345678910111213141516171819202122232425
  1. <?php
  2. namespace App\Modules\Admin\Services;
  3. use App\Exceptions\ClientException;
  4. use App\Models\User;
  5. class AuthService
  6. {
  7. public function login($data)
  8. {
  9. $u = User::wherePhone($data['username'])->orWhere("email",$data['username'])->first();
  10. if(is_null($u)) {
  11. throw new ClientException("账号或密码错误,请重新输入");
  12. }
  13. if(!$u->checkPassword($data['password'])) {
  14. throw new ClientException("账号或密码错误,请重新输入!");
  15. }
  16. if($u->status != User::STATUS_OK) {
  17. throw new ClientException("当前用户被禁用,请联系管理员");
  18. }
  19. return $u;
  20. }
  21. }