// POST api/<controller> public async Task <string> Post(RegistrationSatusModel value) { string id = null; string result = "Ok"; var nus = new NHibernateUserStore(); UserModel user = null; if (HttpContext.Current.Session["UserId"] != null) { id = HttpContext.Current.Session["UserId"].ToString(); } if (id == null) { user = await nus.FindByStampAsync(CurrentUserSession.userSecurityStampCookie); } else { user = await nus.FindByIdAsync(id); } var nds = new NHibernateDriverStore(); var driver = nds.FindByIdAsync(value.Id).Result; var existingUser = await nus.FindByNameAsync(driver.Email); driver.Status = RegistrationStatus.Accepted; driver.UpdatedBy = user; if (existingUser != null) { existingUser.Driver = driver; await nus.UpdateAsync(existingUser); } else { var usr = new UserModel { UserName = driver.Email, FirstName = driver.FirstName, LastName = driver.LastName, PasswordHash = driver.Password, SecurityStamp = Guid.NewGuid().ToString(), Driver = driver }; await nus.CreateAsync(usr); } var emails = driver.Email; await Emailer.SendMessage(driver.Email + " Activated", emails, "Registration"); return(result); }
// POST api/<controller> public async Task <string> Post(PassengerModel value) { string result = "Ok"; PasswordHasher ph = new PasswordHasher(); var passHash = ph.HashPassword(value.Password); var hps = new NHibernatePassengerStore(); var passenger = new PassengerModel { Email = value.Email, FirstName = value.FirstName, LastName = value.LastName, MiddleName = value.MiddleName, BirthDate = value.BirthDate, Gender = value.Gender, Town = value.Town, Province = value.Province, City = value.City, MobileNumber = value.MobileNumber, Password = passHash }; var nhus = new NHibernateUserStore(); var existingUser = await nhus.FindByNameAsync(passenger.Email); try { if (existingUser != null) { existingUser.Passenger = passenger; await nhus.UpdateAsync(existingUser); } else { var usr = new UserModel { UserName = passenger.Email, FirstName = passenger.FirstName, LastName = passenger.LastName, PasswordHash = passenger.Password, SecurityStamp = Guid.NewGuid().ToString(), Passenger = passenger }; await nhus.CreateAsync(usr); } } catch (Exception e) { result = e.Message; } return(result); }
public static async void SignInUser(UserModel user, bool remeberMe) { //CurrentUserSession.userSession = user.Id; if (remeberMe) { if (user.SecurityStamp == null) { user.SecurityStamp = Guid.NewGuid().ToString(); NHibernateUserStore hs = new NHibernateUserStore(); await hs.UpdateAsync(user); } CurrentUserSession.userSecurityStampCookie = user.SecurityStamp; } else { CurrentUserSession.removeSecurityStampCookie(); } }