/// <summary> /// /// </summary> /// <param name="account"></param> /// <param name="emailCategory"></param> private void SendMail(User account,GF.Infrastructure.Crosscutting.Context.HostSendMail.EmailCategory emailCategory) { EMail emailModel = CreateEmail(account, emailCategory); HostSendMail hostSendMail = HostSendMail.CreateHostSendMail(); hostSendMail.SendMail(emailModel); }
public void Register(User user) { if (user == null) throw new ArgumentNullException("user"); using (UserRepository userRepository = new UserRepository()) { if (userRepository.CheckAccountExistByName(user.UserName)) { // throw account name exists exception throw new AccountIsExistException(string.Format(Resource.UserMessages.ex_AccountExist, user.UserName)); } var accounts = userRepository.GetFiltered(a => a.Email == user.Email); if (accounts.Count<User>() > 0) { // throw email exists exception throw new AccountEmailExistException(string.Format(Resource.UserMessages.ex_EmailExist, user.Email)); } userRepository.Add(user); userRepository.Commit(); } }
/// <summary> /// /// </summary> /// <param name="account"></param> /// <returns></returns> private EMail CreateEmail(User account, GF.Infrastructure.Crosscutting.Context.HostSendMail.EmailCategory emailCategory) { EMail activeMail = EMail.CreateEMail(); activeMail.UserName = "******"; activeMail.Password = "******"; activeMail.MailFrom = "*****@*****.**"; activeMail.DisplaySenderName = "GloriousFuture"; activeMail.MailToList.Add(account.Email); activeMail.MailCCList = new List<string>(); activeMail.MailBCCList = new List<string>(); activeMail.Encoding = Encoding.UTF8; switch (emailCategory) { case HostSendMail.EmailCategory.ActivationCode: activeMail.Subject = Resource.UserMessages.info_EmailSubjectActivationCode; activeMail.ContentBody = string.Format(Resource.UserMessages.info_EmailContentBodyActivationCode,account.UserName); break; case HostSendMail.EmailCategory.ResetPassword: activeMail.Subject = Resource.UserMessages.info_EmailContentBodyResetPassword; activeMail.ContentBody = string.Format(Resource.UserMessages.info_EmailContentBodyResetPassword, account.UserName); break; case HostSendMail.EmailCategory.ChangePassword: activeMail.Subject = Resource.UserMessages.info_EmailSubjectChangePassword; activeMail.ContentBody = string.Format(Resource.UserMessages.info_EmailContentBodyChangePassword, account.UserName); break; case HostSendMail.EmailCategory.Recharge: activeMail.Subject = Resource.UserMessages.info_EmailSubjectRecharge; activeMail.ContentBody = string.Format(Resource.UserMessages.info_EmailContentBodyRecharge, account.UserName); break; default: break; } activeMail.Host = "smtp.163.com"; //mailEntity.Port = 465; activeMail.TimeOut = 999999; activeMail.Encoding = Encoding.UTF8; //Encoding.GetEncoding("GB2312"); ; activeMail.IsBodyHtml = true; activeMail.EnableSSL = true; return activeMail; }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { //WebSecurity.CreateUserAndAccount(model.AccountName, model.Password); //WebSecurity.Login(model.AccountName, model.Password); //var membershipUser = Membership.CreateUser(model.UserName, model.Password, model.Email); //var user = userService.GetUser(model.UserName); //userService.ChangeUser(model.UserName, model.QQ, true); var user = new Domain.User(Guid.NewGuid(), model.UserName, model.Password, model.Email, model.QQ); var role = new Domain.Role(); if (model.UniversityId != Guid.Empty) { role = userService.GetRole(Domain.RoleType.企业.ToString()); user.UniversityId = model.UniversityId; } else role = userService.GetRole(Domain.RoleType.个人.ToString()); user.RoleId = role.Id; userService.Register(user); FormsAuthentication.SetAuthCookie(model.UserName, false); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return Register(); }
/// <summary> ///A test for LockAccount ///</summary> public void LockAccountTest() { User target = new User(); target.LockAccount(); Assert.AreEqual(target.IsLocked, true); }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
/// <summary> /// Create a new User object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="userName">Initial value of the UserName property.</param> /// <param name="password">Initial value of the Password property.</param> /// <param name="email">Initial value of the Email property.</param> /// <param name="coins">Initial value of the Coins property.</param> /// <param name="isLocked">Initial value of the IsLocked property.</param> /// <param name="gender">Initial value of the Gender property.</param> /// <param name="isIDCardValid">Initial value of the IsIDCardValid property.</param> /// <param name="lastActivityDate">Initial value of the LastActivityDate property.</param> /// <param name="roleId">Initial value of the RoleId property.</param> public static User CreateUser(global::System.Guid id, global::System.String userName, global::System.String password, global::System.String email, global::System.Int32 coins, global::System.Boolean isLocked, global::System.Boolean gender, global::System.Boolean isIDCardValid, global::System.DateTime lastActivityDate, global::System.Guid roleId) { User user = new User(); user.Id = id; user.UserName = userName; user.Password = password; user.Email = email; user.Coins = coins; user.IsLocked = isLocked; user.Gender = gender; user.IsIDCardValid = isIDCardValid; user.LastActivityDate = lastActivityDate; user.RoleId = roleId; return user; }
public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { status = MembershipCreateStatus.ProviderError; var id = Guid.NewGuid(); var user = new User(id, username, password, email, 0, string.Empty, string.Empty); try { userService.Register(user); status = MembershipCreateStatus.Success; } catch (AccountIsExistException) { status = MembershipCreateStatus.DuplicateUserName; return null; } catch (AccountEmailExistException) { status = MembershipCreateStatus.DuplicateEmail; return null; } return GetUser(username, true); }