public async Task <string> Register(RegisterJSON input) { var user = await _userManager.FindByNameAsync(input.Login); if (user != null) { _logger.LogDebug("Account with username " + input.Login + " already exists."); return("3"); } user = await _userManager.FindByEmailAsync(input.Email); if (user != null) { _logger.LogDebug("Account with email " + input.Email + " already exists."); return("2"); } user = new IdentityUser { UserName = input.Login, Email = input.Email }; var result = await _userManager.CreateAsync(user, input.Password); if (!result.Succeeded) { return("0"); } _logger.LogInformation("Created new account with username " + input.Login); return(user.Id); }
public async Task <JObject> register(RegisterJSON registerJson) { var client = _clientFactory.CreateClient("auth"); var response = await client.PostAsync( "connect/register", new FormUrlEncodedContent(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("Login", registerJson.Login), new KeyValuePair <string, string>("Email", registerJson.Email), new KeyValuePair <string, string>("Password", registerJson.Password) })); var str = await response.Content.ReadAsStringAsync(); _logger.LogInformation("Response from authServer: " + str); if (str.Length <= 1) { return(JObject.Parse("{\"RegisterStatus\": " + str + "}")); } var user = new User { ID_User = str, Login = registerJson.Login, Email = registerJson.Email, Rate = null, isBlocked = false, IDRole = 1 //TODO: assign proper role ID }; var personalData = new PersonalData { IDUser = str, FirstName = registerJson.Name, LastName = registerJson.Surname }; await TrueHomeContext.addUser(user); await TrueHomeContext.addPersonalData(personalData); return(JObject.Parse("{\"RegisterStatus\": 1}")); }