protected void ResetPass_Click(object sender, EventArgs e) { string code = Verification.Text.ToString(); string pass = Password.Text.ToString(); passReset reset = null; using (var ctx = new CVGSEntities()) { reset = ctx.passResets .Where(s => s.resetCode == code).FirstOrDefault(); if (reset != null) { login log = new login(); log.username = reset.username; log.password = pass; if (ModelState.IsValid) { ctx.Entry(log).State = System.Data.Entity.EntityState.Modified; ctx.SaveChanges(); ctx.passResets.Remove(reset); ctx.SaveChanges(); } Response.Redirect("~/Account/Login"); } else { ErrorMessage.Text = "Invalid Verification Code"; } } }
private bool checkLoginStatus(string enteredUser, string enteredPass) { IList <LoginModel> logins = null; bool result = false; using (var ctx = new CVGSEntities()) { logins = ctx.logins.Select(s => new LoginModel() { user = s.username, pword = s.password }).ToList <LoginModel>(); } string usr = null; foreach (var log in logins) { if (enteredUser == log.user && enteredPass == log.pword) { result = true; usr = log.user; Session["Check"] = true; Session["User"] = enteredUser; } } //grab if user is employee and if so make Session["Emp"] = true UserModel login = null; using (var ctx = new CVGSEntities()) { login = ctx.users .Where(s => s.username == enteredUser) .Select(s => new UserModel() { username = s.username, firstName = s.firstName, lastname = s.lastName, email = s.email, mailAddress = s.mailAddress, shipAddress = s.shipAddress, age = s.age, employee = s.employee, }).FirstOrDefault <UserModel>(); } if (login.employee == true) { Session["Emp"] = true; } return(result); }
protected void Forgot(object sender, EventArgs e) { String email = email = Email.Text.Trim(); String code = GetUniqueKey(6); UserModel login = null; using (var ctx = new CVGSEntities()) { login = ctx.users .Where(s => s.email == email) .Select(s => new UserModel() { username = s.username, firstName = s.firstName, lastname = s.lastName, email = s.email, mailAddress = s.mailAddress, shipAddress = s.shipAddress, age = s.age, employee = s.employee, }).FirstOrDefault <UserModel>(); } passReset resetPass = new passReset(); resetPass.resetCode = code; resetPass.username = login.username; using (var ctx = new CVGSEntities()) { if (ModelState.IsValid) { ctx.passResets.Add(resetPass); ctx.SaveChanges(); } } System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.To.Add(email); message.Subject = "CVGS password reset code"; message.From = new System.Net.Mail.MailAddress("*****@*****.**"); message.Body = "Please enter the following code on the reset password page of CVGS: " + code; System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp-mail.outlook.com"); smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "CVGSPassword"); smtp.EnableSsl = true; smtp.Send(message); Response.Redirect("~/Account/ResetPassword"); }
protected void ChangePass_Click(object sender, EventArgs e) { String oldPassword = ""; String newPassword = ""; String user = Session["User"].ToString(); LoginModel logins = null; using (var ctx = new CVGSEntities()) { logins = ctx.logins .Where(s => s.username == user) .Select(s => new LoginModel() { user = s.username, pword = s.password }).FirstOrDefault <LoginModel>(); } if (OldPass.Text.Trim() != null || OldPass.Text.Trim() != "") { oldPassword = OldPass.Text.Trim(); } if (NewPassword.Text.Trim() != null || NewPassword.Text.Trim() != "") { newPassword = NewPassword.Text.Trim(); } if (logins.pword == oldPassword) { login log = new login(); log.username = user; log.password = newPassword; using (var ctx = new CVGSEntities()) { if (ModelState.IsValid) { ctx.Entry(log).State = EntityState.Modified; ctx.SaveChanges(); } } Response.Redirect("/Default"); } else { ErrorMessage.Text = "Current password does not match entered value."; } }
// // GET: /Manage/Index public async Task<ActionResult> Index(ManageMessageId? message) { CVGSEntities db = new CVGSEntities(); ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set." : message == ManageMessageId.Error ? "An error has occurred." : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added." : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed." : ""; var userId = User.Identity.GetUserId(); CVGSUser user = db.CVGSUsers.Where(u => u.userLink == userId).First(); bool receivePromotions = false; if(user.recievePromotions == "1") { receivePromotions = true; } ViewBag.GenresList = new SelectList(db.Genres, "genreID", "genre1", user.favouriteGenre); ViewBag.PlatformsList = new SelectList(db.Platforms, "platformID", "platform1", user.favouritePlatform); var model = new IndexViewModel { HasPassword = HasPassword(), PhoneNumber = await UserManager.GetPhoneNumberAsync(userId), TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId), Logins = await UserManager.GetLoginsAsync(userId), BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId), ReceivePromotions = receivePromotions }; return View(model); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, Address = model.Address, City = model.City, Province = model.Province, Gender = model.Gender, PostalCode = model.PostalCode, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); //Adds the user to the CVGS database, since we wanted to use the ASP default user system CVGSEntities db1 = new CVGSEntities(); CVGSUser newUser = new CVGSUser(); newUser.userID = 1; newUser.firstName = model.FirstName; newUser.lastName = model.LastName; newUser.userName = model.UserName; newUser.email = model.Email; newUser.province = model.Province; newUser.password = "******"; newUser.gender = model.Gender; newUser.recievePromotions = "1"; newUser.userLink = user.Id; newUser.userType = 1; db1.CVGSUsers.Add(newUser); db1.SaveChanges(); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form ViewBag.Province = new SelectList(db.Provinces, "provinceCode", "province1"); return View(model); }
public ActionResult Register() { db = new CVGSEntities(); ViewBag.Province = new SelectList(db.Provinces, "provinceCode", "province1"); return View(); }
public ActionResult Index(IndexViewModel model) { CVGSEntities db = new CVGSEntities(); var userId = User.Identity.GetUserId(); CVGSUser user = db.CVGSUsers.Where(u => u.userLink == userId).FirstOrDefault(); //Updates preferences user.favouriteGenre = int.Parse(Request["GenresList"]); user.favouritePlatform = int.Parse(Request["PlatformsList"]); ViewBag.GenresList = new SelectList(db.Genres, "genreID", "genre1", user.favouriteGenre); ViewBag.PlatformsList = new SelectList(db.Platforms, "platformID", "platform1", user.favouritePlatform); if (model.ReceivePromotions == true) { user.recievePromotions = "1"; } else { user.recievePromotions = "0"; } db.SaveChanges(); return View(model); }
public EventController(CVGSEntities context) { _context = context; }
protected void CreateUser_Click(object sender, EventArgs e) { String email = ""; String uName = ""; String password = ""; String fName = ""; String lName = ""; Int16 age = 10; Boolean isEmployee = false; Boolean invalidUserName = false; IList <LoginModel> logins = null; bool result = false; using (var ctx = new CVGSEntities()) { logins = ctx.logins.Select(s => new LoginModel() { user = s.username, pword = s.password }).ToList <LoginModel>(); } if (Email.Text.Trim() != null || Email.Text.Trim() != "") { email = Email.Text.Trim(); } if (userName.Text.Trim() != null || userName.Text.Trim() != "") { foreach (LoginModel row in logins) { if (userName.Text.Trim() == row.user.ToString()) { ErrorMessage.Text = "Invalid user name"; invalidUserName = true; } } uName = userName.Text.Trim(); } if (firstName.Text.Trim() != null || firstName.Text.Trim() != "") { fName = firstName.Text.Trim(); } if (lastName.Text.Trim() != null || lastName.Text.Trim() != "") { lName = lastName.Text.Trim(); } if (Password.Text.Trim() != null || Password.Text.Trim() != "") { password = Password.Text.Trim(); } age = Convert.ToInt16(Age.Text.Trim()); isEmployee = Employee.Checked; user usr = new user(); usr.username = uName; usr.email = email; usr.firstName = fName; usr.lastName = lName; usr.mailAddress = null; usr.shipAddress = null; usr.age = age; usr.employee = isEmployee; usr.favGenre = null; usr.favGenre2 = null; usr.favPlatform = null; usr.favPlatform2 = null; usr.promoEmails = true; usr.publicWishlist = true; login log = new login(); log.username = uName; log.password = password; if (!invalidUserName) { using (var ctx = new CVGSEntities()) { if (ModelState.IsValid) { ctx.users.Add(usr); ctx.logins.Add(log); ctx.SaveChanges(); } } userName.Text = ""; firstName.Text = ""; lastName.Text = ""; Age.Text = ""; Email.Text = ""; Response.Redirect("/Account/Login"); } }