public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); LogApi.Log(User.Identity.GetUserId(), "Forgot Password" + user.PhoneNumber); // If user has to activate his email to confirm his account, the use code listing below //if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id))) //{ // return Ok(); //} try { using (DAVEntities db = new DAVEntities()) { var token = db.tbl_DeviceIds.Where(d => d.col_UserType == "Admin").FirstOrDefault().col_DeviceToken; Notifications.NotifyAsync(token, "Forgot password", user.PhoneNumber); } } catch (Exception ex) { } if (user == null) { return(Ok("User does not exist")); } string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); //Create URL with above token //http://www.auggi.com:1962/Account/ResetPassword?code=Qb7woiFq0Ml%2Bbwrhw%2BfRf0bJtTVLLC0AuDw%2FuTmlniI1eGW%2By2ocV0EoKTlsAQsODRy3G0XnxuKesB2RJwtMhxLmBEHNi0IM6Drq69f63o4HbxvLzUeSNp7C%2FcwP%2BEVJvwSldnnkoCCuatS2vcgyquAGSBmHcDupxYj7P%2FAGB4mNLcl2QJlIvIEIeOoyDLKVfwdIUw8lwVQTMwndZ29NDQ%3D%3D var lnkHref = "<a href=http://www.auggi.com:1962/Account/ResetPassword?code=" + HttpUtility.UrlEncode(code) + ">Reset Password</a>"; //var lnkHref = "<a href=http://localhost:3773/Account/ResetPassword?code=" + HttpUtility.UrlEncode(code) + ">Reset Password</a>"; //HTML Template for Send email string message = "<b>Please find the Password Reset Link. </b><br/>" + lnkHref; await UserManager.SendEmailAsync(user.Id, "Reset Password", message); return(Ok("Success")); } // If we got this far, something failed, redisplay form return(BadRequest(ModelState)); }
public IHttpActionResult RegistrationTry(RegisterBindingModel model) { AspNetUsersRegistring user = null; try { DAVEntities db = new DAVEntities(); user = new AspNetUsersRegistring(); user.FirstName = model.FirstName; user.LastName = model.LastName; user.DateOfBirth = model.DateOfBirth; user.Address = model.Address; user.City = model.City; user.State = model.State; user.PostalCode = model.PostalCode; user.PhoneNumber = model.PhoneNumber; user.RollNo = model.RollNo; user.Posting = model.Posting; user.JoiningYear = model.JoiningYear; user.LeavingYear = model.LeavingYear; user.BloodGroup = model.BloodGroup; user.House = model.House; user.Designation = model.Designation; user.Department = model.DepartMent; user.School = model.School; user.Password = model.Password; user.ConfirmPassword = model.ConfirmPassword; user.DateTime = DateTime.Now; user.UserName = model.UserName; user.Email = model.Email; user.ProfileLink = model.ProfileLink; db.AspNetUsersRegistrings.Add(user); db.SaveChanges(); return(Ok("Success")); } catch (Exception ex) { return(Ok("Error" + user)); } }
public async Task <IHttpActionResult> Register(RegisterBindingModel model) { try { RegistrationTry(model); } catch { } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = model.UserName, Email = model.Email }; // Add the Address properties: user.FirstName = model.FirstName; user.LastName = model.LastName; user.DateOfBirth = model.DateOfBirth; user.Address = model.Address; user.City = model.City; user.State = model.State; user.PostalCode = model.PostalCode; user.PhoneNumber = model.PhoneNumber; user.RollNo = model.RollNo; user.Posting = model.Posting; user.Latitude = model.Latitude; user.Longitude = model.Longitude; user.JoiningYear = model.JoiningYear; user.LeavingYear = model.LeavingYear; user.BloodGroup = model.BloodGroup; user.House = model.House; user.Designation = model.Designation; user.Department = model.DepartMent; user.School = model.School; user.Profession = model.Profession; user.ShowLocation = model.ShowLocation; user.PhoneVisible = model.PhoneVisible; user.PhoneVisible = model.PhoneVisible; user.ProfileLink = model.ProfileLink; //user.Photo = byteArrayToImage(model.Image); IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } else { await this.UserManager.AddToRoleAsync(user.Id, model.UserRole); } try { using (DAVEntities db = new DAVEntities()) { var token = db.tbl_DeviceIds.Where(d => d.col_UserType == "Admin").FirstOrDefault().col_DeviceToken; Notifications.NotifyAsync(token, "New Registration", model.School + "#" + model.LeavingYear + "#" + user.Id); } } catch (Exception ex) { } return(Ok("Success")); }