public async Task <SignupResponseEnum> SignupAsync(string email, string password, UserProfile userProfile) { try { var profile = await _userProfileRepository.GetByEmailAsync(email); if (profile == null) { var client = new RestSharp.Portable.HttpClient.RestClient( $"{_externalLoginConfigurationService.Auth0DbConnections}{_externalLoginConfigurationService.Auth0DbConnectionsSignUp}"); var request = new RestRequest(Method.POST); client.IgnoreResponseStatusCode = true; var root = new SignUpAuth0User(email, password, _externalLoginConfigurationService.Auth0ClientId, "Username-Password-Authentication" ); string json = JsonConvert.SerializeObject(root); request.AddHeader("Accept", "application/json"); request.AddHeader("content-type", "application/json"); request.AddJsonBody(root); var response = await client.Execute(request); if (response.IsSuccess) { var identityResponse = await this._identityService.RegisterAsync(userProfile); return(SignupResponseEnum.NeedEmailConfirmation); } else { var error = JsonConvert.DeserializeObject <ResponseError>(response.Content); if (error.Error == "invalid_user_password" || error.Error == "invalid_request") { return(SignupResponseEnum.EmailExist); } //if (error.Error == "unauthorized") // return SignupResponseEnum.NeedEmailConfirmation; } return(SignupResponseEnum.Registered | SignupResponseEnum.NeedEmailConfirmation); } else { return(SignupResponseEnum.EmailExist); } } catch (Exception ex) { await _loggerService.LogErrorAsync(ex); throw; } }
public async Task SignupDummysync() { try { var clientJson = new RestSharp.Portable.HttpClient.RestClient( $"http://beta.json-generator.com/api/json/get/Nk1dgANsf"); var requestJson = new RestRequest(Method.GET); clientJson.IgnoreResponseStatusCode = true; var responseJson = await clientJson.Execute(requestJson); var responseParse = JsonConvert.DeserializeObject <List <UserProfile> >(responseJson.Content); foreach (var userProfile in responseParse) { var client = new RestSharp.Portable.HttpClient.RestClient( $"{_externalLoginConfigurationService.Auth0DbConnections}{_externalLoginConfigurationService.Auth0DbConnectionsSignUp}"); var request = new RestRequest(Method.POST); client.IgnoreResponseStatusCode = true; var root = new SignUpAuth0User(userProfile.Email, "Password", _externalLoginConfigurationService.Auth0ClientId, "Username-Password-Authentication" ); string json = JsonConvert.SerializeObject(root); request.AddHeader("Accept", "application/json"); request.AddHeader("content-type", "application/json"); request.AddJsonBody(root); var response = await client.Execute(request); if (response.IsSuccess) { var identityResponse = await this._identityService.RegisterAsync(userProfile); } } } catch (Exception ex) { await _loggerService.LogErrorAsync(ex); throw; } }