public ActionResult ForgotPassword([Bind(Include = "Id, Mail, ForgotPasswordKey, Password")] User user) { if (@Session["UserMail"] == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { var forgetfulUser = db.Users.Where(registeredUser => registeredUser.Mail.Equals(user.Mail) && registeredUser.ForgotPasswordKey.Equals(user.ForgotPasswordKey)).FirstOrDefault(); if (forgetfulUser != null) //good mail and forgotPasswordKey { forgetfulUser.Password = user.Password; db.Entry(forgetfulUser).State = EntityState.Modified; db.SaveChanges(); Response.Write("<script>alert('Your password have been changed');</script>"); return(RedirectToAction("Login")); } else { Response.Write("<script>alert('Incorrect e-mail addres or forgotPassword key');</script>"); return(View()); } } return(View(user)); }
/// <summary> /// Update User /// </summary> /// <param name="user">User info to update</param> /// <returns>Boolean</returns> public async Task <bool> UpdateUserAsync(User user) { if (user.UserId < 0) { _logger.LogDebug("Tried to update Main User"); return(false); } User userForUpdate = await _context.Users.FindAsync(user.UserId); if (userForUpdate != null) { if (userForUpdate.isPermanent) { _logger.LogDebug("Tried to update Permanent User"); return(false); } } if (!_checkEmailService.IsAlreadyTaken(user.Email) || user.Email == userForUpdate.Email) { try { userForUpdate.Email = user.Email; if (user.Password != null) { userForUpdate.Password = new HashService().Hash(user.Password); } else { _context.Entry(userForUpdate).Property(u => u.Password).IsModified = false; } userForUpdate.Name = user.Name; userForUpdate.Surname = user.Surname; userForUpdate.IsActive = user.IsActive; await _context.SaveChangesAsync(); _logger.LogInformation($"User {user.Email} information updated"); return(true); } catch (Exception ex) { _logger.LogWarning(ex.ToString()); return(false); } } return(false); }
public ActionResult Edit([Bind(Include = "Name,Date,MaxAmountOfUsers, Discipline, Sponsors, DateToRegister")] Tournament tournament) { if (@Session["UserMail"] == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { db.Entry(tournament).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tournament)); }
/// <summary> /// Edites portal info /// </summary> /// <param name="portal">Portal to edit</param> /// <returns>Edited portal (or null if not found or error)</returns> public async Task <Portal> EditPortalAsync(Portal portal) { try { var portalInDb = await _context.Portals.FindAsync(portal.Id); if (portalInDb != null) { portalInDb.Name = portal.Name; portalInDb.Type = portal.Type; portalInDb.URL = portal.URL; portalInDb.Parameters = portal.Parameters; portalInDb.Status = portal.Status; portalInDb.Email = portal.Email; portalInDb.CheckInterval = portal.CheckInterval; portalInDb.ResponseTimeThreshold = portal.ResponseTimeThreshold; portalInDb.Method = portal.Method; portalInDb.BasicAuth = portal.BasicAuth; portalInDb.UserName = portal.UserName; if (portal.BasicAuth && !string.IsNullOrEmpty(portal.PasswordHashed)) { portalInDb.PasswordHashed = portal.PasswordHashed; } else { _context.Entry(portalInDb) .Property(u => u.PasswordHashed).IsModified = false; } await _context.SaveChangesAsync(); _logger.LogInformation("Portal (Id: {0}) edited.", portal.Id); return(portalInDb); } _logger.LogWarning("Portal (Id: {0}) not found for editing.", portal.Id); return(null); } catch (Exception ex) { _logger.LogError(ex.Message); return(null); } }