public void RegisterUser(string email, string username, string password, string firstname, string surname, DateTime birth, string gender, string mobile, string picture, string address) { PickrWebService api = new PickrWebService(); JSONParser parser = new JSONParser(); UserDetails u = new UserDetails(); JObject json = api.CreateUser(email, username, password, firstname, surname, birth, gender, mobile, picture, address); //bool valid = parser.ParseCreateNewUser(json); var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>(); var user = new ApplicationUser() { UserName = email, Email = email }; IdentityResult result = manager.Create(user, password); var b = result.Succeeded; if (b) { bool added = false; added = parser.ParseCreateTable(json); if (added) { u.Email = email; u.Password = password; u.Username = username; u.FirstName = firstname; u.Surname = surname; u.Birth = birth; u.Gender = gender; u.Picture = picture; u.Address = address; u.MemberSince = DateTime.Now; HttpContext.Current.Session["User"] = u; signInManager.SignIn(user, isPersistent: false, rememberBrowser: false); //IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); Response.Redirect("~/Default"); } else if (!added) { ErrorMessage.Text = "A user already exists with the same Username or Email you provided."; manager.Delete(user); } } else { ErrorMessage.Text = result.Errors.FirstOrDefault(); } }
public void RegisterUser(string email, string username, string password, string firstname, string surname, DateTime birth, string gender, string mobile, string address) { PickrWebService api = new PickrWebService(); JSONParser parser = new JSONParser(); UserDetails u = new UserDetails(); DateTime membersince = DateTime.Now; string picture = "http://www.pickrwebservice.somee.com/images/profile/default-" + gender + ".jpg"; //bool valid = parser.ParseCreateNewUser(json); //Create in localDB var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>(); var user = new ApplicationUser() { UserName = email, Email = email }; IdentityResult result = manager.Create(user, password); var b = result.Succeeded; //End create in localDB if (b) { bool added = false; JObject json = api.CreateUser(email, username, password, firstname, surname, birth, gender, mobile, picture, address); added = parser.ParseCreateTable(json); if (added) { u.Email = email; u.Password = password; u.Username = username; u.FirstName = firstname; u.Surname = surname; u.Birth = birth; u.Gender = gender; u.MemberSince = membersince; u.Mobile = mobile; u.Picture = picture; u.Address = address; HttpContext.Current.Session["User"] = u; //Signin localDB signInManager.SignIn(user, isPersistent: false, rememberBrowser: false); //IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); //End signin localDB Response.Redirect("/PassengerHome"); } else if (!added) { ErrorMessage.Text = "The Username or Email you provided are already taken by another user."; //Delete from localDB manager.Delete(user); //End delete from localDB } } else { ErrorMessage.Text = result.Errors.FirstOrDefault(); } }