public async Task <IActionResult> ExternalLogin([FromBody] ExternalLoginViewModel auth) { if (!ModelState.IsValid) { return(new BadResponseResult(ModelState)); } if (auth.State != "S5ocialCode!129_Code") { ModelState.AddModelError("State", "You are hacker! Your state is incorrect."); return(new BadResponseResult(ModelState)); } if (!auth.Error.IsNullOrEmpty()) { ModelState.AddModelError("ExternalError", "ExternalError: " + auth.Error + " " + auth.ErrorDescription); return(new BadResponseResult(ModelState)); } if (string.IsNullOrEmpty(auth.Code)) { ModelState.AddModelError("Code", "Code is null or empty."); return(new BadResponseResult(ModelState)); } var userDto = await _externalAuthService.GetUserViaExternalSocialNet(auth.Code, auth.SocialType, auth.IsTest); var result = await _commonAuthService.Login(userDto); return(new OkResponseResult(result)); }
public async Task <IActionResult> Login([FromBody] LoginViewModel credentials) { if (!ModelState.IsValid) { return(new BadResponseResult(ModelState)); } if ((credentials.GrantType == GrantType.Phone || credentials.GrantType == GrantType.Email) && credentials.Password.IsNullOrEmpty()) { ModelState.AddModelError("Password", "Password is null or empty, but grant type is not guest."); return(new BadResponseResult(ModelState)); } var user = new UserDto { UserId = 0, RoleType = RoleType.Guest }; switch (credentials.GrantType) { case GrantType.Guest: break; case GrantType.Phone: user = await _internalAuthService.GetUserByPhone(credentials.Phone, credentials.Password); if (user == null) { return(new ResponseResult((int)HttpStatusCode.Forbidden, "Phone and(or) password is incorrect", new { Token = new Token(), User = new UserInfoViewModel() })); } break; case GrantType.Email: user = await _internalAuthService.GetUserByEmail(credentials.Email, credentials.Password); if (user == null) { return(new ResponseResult((int)HttpStatusCode.Forbidden, "Email and(or) password is incorrect", new { Token = new Token(), User = new UserInfoViewModel() })); } break; default: ModelState.AddModelError("GrantType", "Sorry, we can not find such grant type."); return(new BadResponseResult(ModelState)); } var result = await _commonAuthService.Login(user); return(new OkResponseResult(result)); }