/// <summary> /// /// </summary> /// <param name="pollId"></param> /// <param name="pollChoiceId"></param> public void AnswerPoll(long pollId, long pollChoiceId) { awPollChoice choice = (from l in _context.awPollChoices where l.pollId.Equals(pollId) && l.pollChoiceId.Equals(pollChoiceId) && l.awPoll.isEnabled && l.awPoll.awSite_Poll.isEnabled select l).FirstOrDefault <awPollChoice>(); if (choice == null) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.DOES_NOT_EXIST)); } int dateBetween = MiscLibrary.IsDateBetween(DateTime.Now, choice.awPoll.pubDate, choice.awPoll.pubEndDate); switch (dateBetween) { case -1: throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.NOT_PUBLISHED)); break; case 0: throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.POLL.EXPIRED)); break; } choice.numberOfVotes += 1; choice.lastBuildDate = DateTime.Now; _context.SubmitChanges(); }
public void ResetPassword(long siteId, string email, string redirectLink) { awSite site = new SiteLibrary().Get(siteId); if (site == null || !site.isEnabled) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.SITE.DOES_NOT_EXIST)); } if (site.userResetPasswordEmailTemplateId == null) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.SITE.RESET_PASSWORD_TEMPLATE_DOES_NOT_EXIST)); } //GET THE USER awUser user = (from l in _context.awUsers where l.email.Equals(email) && l.isEnabled != false select l).FirstOrDefault(); if (user == null) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.DOES_NOT_EXIST)); } //CREATE NEW PASSWORD const int PASSWORD_LENGTH = 6; string _allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789"; Random randNum = new Random(); char[] chars = new char[PASSWORD_LENGTH]; int allowedCharCount = _allowedChars.Length; for (int i = 0; i < PASSWORD_LENGTH; i++) { chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())]; } string password = new string(chars); //FIRST SEND EMAIL BEFORE RESETING THE PASSWORD AWAPI_BusinessLibrary.library.EmailTemplateLib emailLib = new EmailTemplateLib(); awEmailTemplate template = emailLib.Get(site.userResetPasswordEmailTemplateId.Value); if (template == null) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.SITE.RESET_PASSWORD_TEMPLATE_DOES_NOT_EXIST)); } emailLib.Send(site.userResetPasswordEmailTemplateId.Value, email, "firstname|" + user.firstName, "lastname|" + user.lastName, "password|" + password, "link|" + redirectLink, "date|" + DateTime.Now.ToString()); //UPDATE PASSWORD UpdatePassword(user.userId, password); }
/// <summary> /// Updates user's password /// </summary> /// <param name="userId"></param> /// <param name="passworc"></param> /// <returns></returns> public bool UpdatePassword(long userId, string password) { if (password.Trim().Length < 6 || password.Trim().Length > 30) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.WRONG_PASSWORD_FORMAT)); } awUser usr = _context.awUsers.FirstOrDefault(st => st.userId.Equals(userId)); if (usr == null) { return(false); } usr.password = new AWAPI_Common.library.SecurityLibrary().EncodeString(password); usr.lastBuildDate = DateTime.Now; _context.SubmitChanges(); return(true); }
public bool ValidateUserInfo(long userId, string userName, string email, string password) { //Check username var usernameExist = from u in _context.awUsers where u.username.ToLower().Equals(userName.ToLower()) && u.userId != userId select u; if (usernameExist != null && usernameExist.Count() > 0) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.USERNAME_IN_USE)); } //check email var emailExists = from u in _context.awUsers where u.email.ToLower().Equals(email.ToLower()) && u.userId != userId select u; if (emailExists != null && emailExists.Count() > 0) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.EMAIL_IN_USE)); } //check password if (password != null) { if (password.Trim().Length < 6 || password.Trim().Length > 30) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.USER.WRONG_PASSWORD_FORMAT)); } } return(true); }
/// <summary> /// /// </summary> /// <param name="contestId"></param> /// <param name="userId"></param> /// <param name="isEnabled"></param> /// <param name="cultureCode"></param> /// <param name="email"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="title"></param> /// <param name="description"></param> /// <param name="fileId"></param> /// <param name="fileUrl"></param> /// <param name="tel"></param> /// <param name="telType"></param> /// <param name="address"></param> /// <param name="city"></param> /// <param name="province"></param> /// <param name="postalCode"></param> /// <param name="country"></param> /// <returns></returns> public long AddContestEntry(long contestId, long?userId, bool isEnabled, string cultureCode, string email, string firstName, string lastName, string title, string description, long?fileId, string fileUrl, string tel, string telType, string address, string city, string province, string postalCode, string country) { long id = AWAPI_Common.library.MiscLibrary.CreateUniqueId(); ContestExtended contest = GetContest(contestId, true); if (contest == null) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.CONTEST.DOES_NOT_EXIST)); } awContestEntry entry = new awContestEntry(); if (String.IsNullOrEmpty(email) || !AWAPI_Common.library.Validation.IsEmail(email)) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.CONTEST.EMAIL_REQUIRED)); } if (String.IsNullOrEmpty(firstName) || String.IsNullOrEmpty(lastName)) { throw new Exception(ErrorLibrary.ErrorMessage(ErrorLibrary.CONTEST.FIRSTNAME_LASTNAME_REQUIRED)); } entry.contestEntryId = id; entry.contestId = contestId; entry.userId = userId; entry.isEnabled = isEnabled; entry.cultureCode = cultureCode; entry.email = email; entry.firstName = firstName; entry.lastName = lastName; entry.title = title; entry.description = description; entry.fileId = fileId; entry.fileUrl = fileUrl; entry.tel = tel; entry.telType = telType; entry.address = address; entry.city = city; entry.province = province; entry.postalCode = postalCode; entry.country = country; entry.createDate = DateTime.Now; _context.awContestEntries.InsertOnSubmit(entry); _context.SubmitChanges(); AWAPI_BusinessLibrary.library.EmailTemplateLib lib = new EmailTemplateLib(); //SEND EMAIL TO THE MODERATORS -------------------- if (contest.sendEmailToModeratorTemplateId != null && !String.IsNullOrEmpty(contest.sendEmailToModeratorRecipes)) { string link = ""; if (entry.fileId != null) { link = ConfigurationLibrary.Config.adminBaseUrl + "admin/files.aspx?fileid=" + entry.fileId.Value.ToString(); } lib.Send(entry.awContest.sendEmailToModeratorTemplateId.Value, contest.sendEmailToModeratorRecipes, "firstname|" + entry.firstName, "lastname|" + entry.lastName, "link|" + link, "date|" + DateTime.Now.ToString()); } //SEND EMAIL TO THE CONTENDER -------------------- if (contest.sendEmailAfterSubmissionTemplateId != null) { lib.Send(entry.awContest.sendEmailAfterSubmissionTemplateId.Value, entry.email, "firstname|" + entry.firstName, "lastname|" + entry.lastName, "date|" + DateTime.Now.ToString()); } return(id); }