public async Task <IActionResult> Authenticate(string firebaseUid, string returnUrl) { try { bool registration_is_required = true; string phoneNumber = await FirebaseService.GetPhoneNumberByUID(firebaseUid); var existingUser = GetUserByPhoneNumber(phoneNumber); if (existingUser != null) { if (existingUser.UserType == UserTypesEnum.talent.ToString() && !existingUser.TalentApprovedByAdmin) { var talent = TalentService.GetByUserID(existingUser.Id); if (talent == null) { throw new Exception("Талант не найден"); } if (!talent.SocialAreaID.HasValue) { throw new Exception("Социальная сеть не указана"); } SocialArea socialArea = SocialAreaService.GetByID(talent.SocialAreaID.Value); if (socialArea == null) { throw new Exception("Социальная сеть не найдена"); } string errorText = @"Ваша заявка как Таланта еще не одобрена. Отправьте нам сообщение на " + socialArea.Name + " " + socialArea.CompanySocialAreaHandle + @" от Вашего " + socialArea.Name + @" аккаунта " + talent.SocialAreaHandle + @" с текстом ""Helloo " + existingUser.TalentConfirmationCode + @""""; throw new Exception(errorText); } else { if (existingUser.UserType == UserTypesEnum.customer.ToString()) { var customer = CustomerService.GetByUserID(existingUser.Id); if (customer == null) { throw new Exception("Клиент не найден"); } } else if (existingUser.UserType == UserTypesEnum.talent.ToString()) { var talent = TalentService.GetByUserID(existingUser.Id); if (talent == null) { throw new Exception("Талант не найден"); } } await _signInManager.SignInAsync(existingUser, true); } registration_is_required = false; } return(Json(new { registration_is_required, returnUrl = CorrectifyReturnUrl(returnUrl) })); } catch (Exception ex) { return(CustomBadRequest(ex)); } }
public async Task <ActionResult <AuthenticateResponseVM> > Authenticate([FromBody] LoginVM login) { bool registrationIsRequired = true; string authToken = null; string userType = null; try { string phoneNumber = await FirebaseService.GetPhoneNumberByUID(login.firebase_uid); var existingUser = GetUserByPhoneNumber(phoneNumber); if (existingUser != null) { if (existingUser.UserType == UserTypesEnum.talent.ToString() && !existingUser.TalentApprovedByAdmin) { var talent = TalentService.GetByUserID(existingUser.Id); if (talent == null) { throw new Exception("Талант не найден"); } if (!talent.SocialAreaID.HasValue) { throw new Exception("Социальная сеть не указана"); } SocialArea socialArea = SocialAreaService.GetByID(talent.SocialAreaID.Value); if (socialArea == null) { throw new Exception("Социальная сеть не найдена"); } string errorText = @"Ваша заявка как Таланта еще не одобрена. Отправьте нам сообщение на " + socialArea.Name + " " + socialArea.CompanySocialAreaHandle + @" от Вашего " + socialArea.Name + @" аккаунта " + talent.SocialAreaHandle + @" с текстом ""Helloo " + existingUser.TalentConfirmationCode + @""""; throw new Exception(errorText); } else { if (existingUser.UserType == UserTypesEnum.customer.ToString()) { var customer = CustomerService.GetByUserID(existingUser.Id); if (customer == null) { throw new Exception("Клиент не найден"); } } else if (existingUser.UserType == UserTypesEnum.talent.ToString()) { var talent = TalentService.GetByUserID(existingUser.Id); if (talent == null) { throw new Exception("Талант не найден"); } } authToken = GenerateAuthToken(existingUser); userType = existingUser.UserType; FirebaseRegistrationTokenService.SaveToken(login.firebase_token, existingUser.Id, "mob"); } registrationIsRequired = false; } } catch (Exception ex) { return(CustomBadRequest(ex)); } return(new AuthenticateResponseVM( registrationIsRequired, authToken, userType)); }