public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { if (!_authRepository.AlreadyExists(model.Email)) { // Try and send the confirmation email first. If that works, and the email is valid, then add it here. var result = _authRepository.Register(model.Email, model.Password); if (result.Success) { // Generate an email confirmation token for this account var token = AuthEncryption.RandomSalt(6); result = _authRepository.SetEmailConfirmationToken(model.Email, token); var secureUrl = Url.Action("ConfirmEmail", "Account", new { e = model.Email, c = token }, "https"); string mailBody = MailCommonStrings.RegisteredBody(secureUrl); Mailer.SendEmail_NoWait(model.Email, MailCommonStrings.RegisteredSubject, mailBody); _logger.Debug($"{model.Email} has successfully registered an account from {ClientIpAddress.GetIPAddress(Request)}"); MvcCaptcha.ResetCaptcha("regoCaptcha"); return(RedirectToAction("ConfirmationRequired")); } ModelState.AddModelError("", result.Message); } else { ModelState.AddModelError("", "An account with this email address already exists!"); } } // If we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Updated for MySQL /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public bool Validate(string username, string password) { var user = GetUserAccount(username); if (user == null) { return(false); } return(AuthEncryption.ValidatePassword(password, user.PasswordHash, user.ExtraInformation2)); }
public async Task <bool> ValidateAsync(string username, string password) { var user = await GetUserAccountAsync(username); if (user == null) { return(false); } return(AuthEncryption.ValidatePassword(password, user.PasswordHash, user.ExtraInformation2)); }
/// <summary> /// Updated for MySQL /// </summary> /// <param name="email"></param> /// <param name="password"></param> /// <returns></returns> public ReturnValue ResetPassword(string email, string password) { string hash; string salt; AuthEncryption.GenerateHashAndSalt(password, out salt, out hash); ReturnValue returnValue = new ReturnValue(); try { var sw = new Stopwatch(); sw.Start(); DapperDb dapperDb = DapperDb.Init(OpenConnection(), 3, false); var userId = GetIdByEmail(email); if (userId == 0) { returnValue.Message = string.Format("No user was found with the email address {0}", email); return(returnValue); } var userToSet = dapperDb.AuthUserTable.Get(userId); var snapshot = Snapshotter.Start(userToSet); userToSet.ExtraInformation2 = salt; userToSet.PasswordHash = hash; userToSet.PasswordResetToken = null; userToSet.AccessFailedCount = 0; DynamicParameters dynamicParameters = snapshot.Diff(); if (!dynamicParameters.ParameterNames.Any()) { sw.Stop(); returnValue.Message = "There was nothing to update!"; return(returnValue); } dapperDb.AuthUserTable.Update(userId, snapshot.Diff()); sw.Stop(); returnValue.Success = true; returnValue.TimeTaken = sw.Elapsed; } catch (Exception ex) { returnValue.Message = ex.Message; } return(returnValue); }
public ActionResult Reverify(ReverifyViewModel model) { if (ModelState.IsValid) { if (_authRepository.AlreadyExists(model.Email)) { var token = AuthEncryption.RandomSalt(6); var result = _authRepository.SetEmailConfirmationToken(model.Email, token); var secureUrl = Url.Action("ConfirmEmail", "Account", new { e = model.Email, c = token }, "https"); //var linkUrl = Url.AbsoluteAction("ConfirmEmail", "Account", new { e = model.Email, c = token }); string mailBody = MailCommonStrings.RegisteredBody(secureUrl); Mailer.SendEmail_NoWait(model.Email, MailCommonStrings.RegisteredSubject, mailBody); _logger.Debug(string.Format("{0} has requested another verification email from {1}", model.Email, ClientIpAddress.GetIPAddress(Request))); } MvcCaptcha.ResetCaptcha("ReverifyCaptcha"); return(RedirectToAction("ReverificationSent")); } return(View()); }
public ActionResult ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { if (_authRepository.AlreadyExists(model.Email)) { var token = AuthEncryption.RandomSalt(6); var result = _authRepository.SetPasswordResetToken(model.Email, token); var userIp = ClientIpAddress.GetIPAddress(Request); var secureUrl = Url.Action("TryResetPassword", "Account", new { e = model.Email, c = token }, "https"); //var linkUrl = Url.AbsoluteAction("TryResetPassword", "Account", new { e = model.Email, c = token }); string mailBody = MailCommonStrings.PasswordResetBody(userIp, secureUrl); Mailer.SendEmail_NoWait(model.Email, MailCommonStrings.ResetPasswordSubject, mailBody); _logger.Debug(string.Format("{0} has requested to reset their password from {1}", model.Email, ClientIpAddress.GetIPAddress(Request))); } MvcCaptcha.ResetCaptcha("ResetPasswordCaptcha"); return(RedirectToAction("PasswordResetSent")); } return(View()); }
public ReturnValue Register(string email, string password) { string hash; string salt; AuthEncryption.GenerateHashAndSalt(password, out salt, out hash); return(Add(new AuthUser() { Email = email, ExtraInformation1 = null, ExtraInformation2 = salt, ShortMenuFormat = true, ShowGuildMenu = true, AccessFailedCount = 0, LockoutEnabled = true, LockoutEndDate = null, PasswordHash = hash, EmailConfirmed = false, TimeZone = "UTC" }, "system")); }
public ReturnValue AddNpcCasts(List <EncounterNpcCast> npcCasts) { var returnValue = new ReturnValue(); try { // Create a CSV of the data, and then dump it into the database string randomFilename = AuthEncryption.RandomFilename() + ".csv"; while (true) { if (!File.Exists("databaseImport\\" + randomFilename)) { break; } randomFilename = AuthEncryption.RandomFilename() + ".csv"; } string filePath = "databaseImport\\" + randomFilename; using (var outFile = File.CreateText(filePath)) { outFile.WriteLine("EncounterId,AbilityName,NpcId,NpcName"); foreach (var cast in npcCasts) { List <object> lineList = new List <object>() { cast.EncounterId, cast.AbilityName, cast.NpcId, cast.NpcName }; outFile.WriteLine(EncapLine(lineList)); } } using (var connection = new MySqlConnection(_connectionString)) { MySqlBulkLoader bulkLoader = new MySqlBulkLoader(connection) { TableName = "EncounterNpcCast", FieldTerminator = ",", LineTerminator = "\r\n", FieldQuotationCharacter = '"', FieldQuotationOptional = false, FileName = filePath, NumberOfLinesToSkip = 1, Columns = { "EncounterId", "AbilityName", "NpcId", "NpcName" } }; int count = bulkLoader.Load(); returnValue.Success = true; returnValue.Message = count.ToString(); } try { File.Delete(filePath); } catch (Exception ex) { // Catch this? } return(returnValue); } catch (Exception ex) { returnValue.Message = ex.Message; return(returnValue); } }
public ReturnValue AddBuffAction(List <EncounterBuffAction> buffActions) { var returnValue = new ReturnValue(); try { // Create a CSV of the data, and then dump it into the database string randomFilename = AuthEncryption.RandomFilename() + ".csv"; while (true) { if (!File.Exists("databaseImport\\" + randomFilename)) { break; } randomFilename = AuthEncryption.RandomFilename() + ".csv"; } string filePath = "databaseImport\\" + randomFilename; using (var outFile = File.CreateText(filePath)) { outFile.WriteLine("EncounterId,AbilityId,BuffName,SourceId,SourceName,SourceType,TargetId,TargetName,TargetType," + "SecondBuffWentUp,SecondBuffWentDown"); foreach (var action in buffActions) { List <object> lineList = new List <object>() { action.EncounterId, action.AbilityId, action.BuffName, action.SourceId, action.SourceName, action.SourceType, action.TargetId, action.TargetName, action.TargetType, action.SecondBuffWentUp, action.SecondBuffWentDown }; if (action.AbilityId == 0) { string something = "blah"; } outFile.WriteLine(EncapLine(lineList)); } } using (var connection = new MySqlConnection(_connectionString)) { MySqlBulkLoader bulkLoader = new MySqlBulkLoader(connection) { TableName = "EncounterBuffAction", FieldTerminator = ",", LineTerminator = "\r\n", FieldQuotationCharacter = '"', FieldQuotationOptional = false, FileName = filePath, NumberOfLinesToSkip = 1, Columns = { "EncounterId", "AbilityId", "BuffName", "SourceId", "SourceName", "SourceType", "TargetId", "TargetName", "TargetType", "SecondBuffWentUp", "SecondBuffWentDown" } }; int count = bulkLoader.Load(); returnValue.Success = true; returnValue.Message = count.ToString(); } try { File.Delete(filePath); } catch (Exception ex) { // Catch this? } return(returnValue); } catch (Exception ex) { returnValue.Message = ex.Message; return(returnValue); } }
public ReturnValue AddEncounterDeaths(List <EncounterDeath> encounterDeaths) { var returnValue = new ReturnValue(); try { // Create a CSV of the data, and then dump it into the database string randomFilename = AuthEncryption.RandomFilename() + ".csv"; while (true) { if (!File.Exists("databaseImport\\" + randomFilename)) { break; } randomFilename = AuthEncryption.RandomFilename() + ".csv"; } string filePath = "databaseImport\\" + randomFilename; using (var outFile = File.CreateText(filePath)) { outFile.WriteLine("SourcePlayerId,SourceNpcName,SourceNpcId,SourcePetName,TargetPlayerId,TargetNpcName,TargetNpcId,TargetPetName," + "EncounterId,AbilityId,TotalDamage,OverkillValue,SecondsElapsed,OrderWithinSecond"); foreach (var death in encounterDeaths) { List <object> lineList = new List <object>() { death.SourcePlayerId, death.SourceNpcName, death.SourceNpcId, death.SourcePetName, death.TargetPlayerId, death.TargetNpcName, death.TargetNpcId, death.TargetPetName, death.EncounterId, death.AbilityId, death.TotalDamage, death.OverkillValue, death.SecondsElapsed, death.OrderWithinSecond }; outFile.WriteLine(EncapLine(lineList)); } } using (var connection = new MySqlConnection(_connectionString)) { MySqlBulkLoader bulkLoader = new MySqlBulkLoader(connection) { TableName = "EncounterDeath", FieldTerminator = ",", LineTerminator = "\r\n", FieldQuotationCharacter = '"', FieldQuotationOptional = false, FileName = filePath, NumberOfLinesToSkip = 1, Columns = { "SourcePlayerId", "SourceNpcName", "SourceNpcId", "SourcePetName", "TargetPlayerId", "TargetNpcName", "TargetNpcId", "TargetPetName", "EncounterId", "AbilityId", "TotalDamage", "OverkillValue", "SecondsElapsed", "OrderWithinSecond" } }; int count = bulkLoader.Load(); returnValue.Success = true; returnValue.Message = count.ToString(); } try { File.Delete(filePath); } catch (Exception ex) { // Catch this? } return(returnValue); } catch (Exception ex) { returnValue.Message = ex.Message; return(returnValue); } }
public ActionResult UploadPart1(UploadSessionVM model) { // Check we have a valid user var user = _authRepository.GetUserAccount(User.Identity.GetUserId()); if (user == null) { HttpContext.GetOwinContext().Authentication.SignOut(); return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { // Generate an upload token and make sure it's not in use while (true) { model.UploadToken = AuthEncryption.RandomFilename(); _logger.Debug(string.Format("Checking to see if session token {0} has been used before", model.UploadToken)); if (!_sessionLogRepository.SessionLogTokenExists(model.UploadToken)) { _logger.Debug("Token wasn't found, so inserting a new session with it now."); break; } _logger.Debug(string.Format("Found an existing log with the token {0} - generating a new one.", model.UploadToken)); } TimeSpan utcOffset = TimeZoneInfo.FindSystemTimeZoneById(user.TimeZone).GetUtcOffset(DateTime.UtcNow); var result = _sessionRepository.CreateSession(User.Identity.GetUserId(), new Session() { AuthUserCharacterId = model.UploadCharacterId, Date = model.SessionDate.Subtract(utcOffset), Name = model.Name, EncountersPublic = model.Public }); if (result.Success) { int sessionId = int.Parse(result.Message); model.UploadedSessionId = sessionId; // Add this session to the SessionLog table in case other guild members or this user choose to upload additional logs to the session var guildId = _authUserCharacterRepository.GetGuildIdForCharacter(model.UploadCharacterId); if (guildId > 0) { var newSessionLog = new SessionLog() { AuthUserCharacterId = model.UploadCharacterId, Filename = model.UploadToken + ".zip", Token = model.UploadToken, GuildId = guildId, LogSize = 0, SessionId = sessionId, TotalPlayedTime = 0 }; var returnValue = _sessionLogRepository.Create(newSessionLog); } return(UploadPart2(model)); } ModelState.AddModelError("", result.Message); } //var user = _authRepository.GetUserAccount(User.Identity.GetUserId()); var userCharacters = _authUserCharacterRepository.GetUploaders(user.Email); model.Characters = userCharacters; return(View(model)); }