public IActionResult Login(UserLoginViewModel user) { try { User inMemUser = _redisCache.Get <User>(user.UserName); // User inMemUser = (User)_memoryCache.Get(user.UserName); if (inMemUser != null) { if (inMemUser.Password.Equals(SBHelper.MD5Hash(user.Password))) { return(Ok(inMemUser)); } else { return(Ok("Wrong Password")); } } } catch (Exception ex) { _logger.LogInformation(ex.Message); _logger.LogError(ex.StackTrace); } DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv); IList <User> lstUser = dbr.Find <User>(t => t.EmailId.Equals(user.UserName)); if (lstUser != null && lstUser.Count() > 0) { if (lstUser.First().Password != null && lstUser.First().Password.Equals(SBHelper.MD5Hash(user.Password))) { DateTime d1 = DateTime.UtcNow; //User userTable = dbr.Single < User>(t => t.EmailId == user.UserName); lstUser.First().LastLoginTime = d1; //userTable.LastLoginTime = d1; dbr.Update <User>(lstUser.First()); // _memoryCache.Set(lstUser.First().EmailId, lstUser.First()); _redisCache.Set <User>(lstUser.First().EmailId, lstUser.First()); if (lstUser.First().ActivationStatus == Domain.Socioboard.Enum.SBUserActivationStatus.Active) { return(Ok(lstUser.First())); } else { return(Ok("Account not activated.")); } } else { return(Ok("Wrong Password")); } } else { return(Ok("EmailId Not Exist")); } }
public IActionResult ChangePassword(long userId, string currentPassword, string newPassword, string conformPassword) { DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv); User user = dbr.Single <User>(t => t.Id == userId); if (user != null && user.Password != null) { if (user.Password.Equals(SBHelper.MD5Hash(currentPassword))) { if (user.Password.Equals(SBHelper.MD5Hash(newPassword))) { return(Ok("Current Password and New Password are same.Try with New Password")); } if (newPassword.Equals(conformPassword)) { user.Password = SBHelper.MD5Hash(newPassword); int res = dbr.Update <User>(user); if (res == 1) { return(Ok("Password Updated")); } else { return(BadRequest("error while updating password, pls try after some time.")); } } else { return(BadRequest("new password and conform password are not matching.")); } } else { return(BadRequest("Wrong password")); } } else { //return Unauthorized(); return(BadRequest("Please Follow The Password Policy One Capital letter, One Small letter, One number, One special character and min lenght must be 8")); } }
public IActionResult ResetPasswordMail(string emailId, string changePassword, string token) { DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv); User user = null; try { user = dbr.Single <User>(t => t.EmailId == emailId); } catch { } if (user != null) { if (user.forgotPasswordKeyToken.Equals(token)) { user.Password = SBHelper.MD5Hash(changePassword); int res = dbr.Update <User>(user); if (res == 1) { return(Ok("Password changed successfully")); } else { return(BadRequest("error while updating password, pls try after some time.")); } } else { return(Ok("wrong link")); } } else { return(Ok("EmailId does not exist")); } }
public IActionResult Register(User user) { user.CreateDate = DateTime.UtcNow; user.ExpiryDate = DateTime.UtcNow.AddDays(1); user.EmailValidateToken = SBHelper.RandomString(20); user.ValidateTokenExpireDate = DateTime.UtcNow.AddDays(1); user.ActivationStatus = Domain.Socioboard.Enum.SBUserActivationStatus.MailSent; user.Password = SBHelper.MD5Hash(user.Password); user.UserName = "******"; user.PayPalAccountStatus = Domain.Socioboard.Enum.PayPalAccountStatus.notadded; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DatabaseRepository dbr = new DatabaseRepository(_logger, _appEnv); IList <User> lstUser = dbr.Find <User>(t => t.EmailId.Equals(user.EmailId)); if (lstUser != null && lstUser.Count() > 0) { return(BadRequest("EmailID Exist")); } IList <User> lstUser1 = dbr.Find <User>(a => a.PhoneNumber.Equals(user.PhoneNumber)); if (lstUser1 != null && lstUser1.Count() > 0) { return(BadRequest("Phone Number Exist")); } int SavedStatus = dbr.Add <Domain.Socioboard.Models.User>(user); User nuser = dbr.Single <User>(t => t.EmailId.Equals(user.EmailId)); if (SavedStatus == 1 && nuser != null) { Groups group = new Groups(); group.adminId = nuser.Id; // group.id = nuser.Id; group.createdDate = DateTime.UtcNow; group.groupName = Domain.Socioboard.Consatants.SocioboardConsts.DefaultGroupName; SavedStatus = dbr.Add <Groups>(group); if (SavedStatus == 1) { long GroupId = dbr.FindSingle <Domain.Socioboard.Models.Groups>(t => t.adminId == group.adminId && t.groupName.Equals(group.groupName)).id; GroupMembersRepository.createGroupMember(GroupId, nuser, _redisCache, dbr); } try { string path = _appEnv.WebRootPath + "\\views\\mailtemplates\\registrationmail.html"; string html = System.IO.File.ReadAllText(path); html = html.Replace("[FirstName]", nuser.FirstName); html = html.Replace("[AccountType]", nuser.AccountType.ToString()); html = html.Replace("[ActivationLink]", _appSettings.Domain + "/Home/Active?Token=" + nuser.EmailValidateToken + "&id=" + nuser.Id); _emailSender.SendMailSendGrid(_appSettings.frommail, "", nuser.EmailId, "", "", "Socioboard Email conformation Link", html, _appSettings.SendgridUserName, _appSettings.SendGridPassword); } catch { return(Ok()); } } else { return(BadRequest("Can't create user")); } return(Ok("Email verification mail sent successfully.")); }