/// <summary> /// 新用户注册 /// </summary> /// <param name="newUser">待注册的新帐号</param> /// <returns>注册是否成功</returns> public Account Register(UserRegisterModel newUser) { Account account = null; //创建账户仓储 IRepository <Account> accountRep = FBS.Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); if (accountRep.Exists(new Specification <Account>(a => a.Email == newUser.Email))) { throw new RegisterException("该邮箱已经被注册"); } if (string.IsNullOrEmpty(newUser.UserName) && string.IsNullOrEmpty(newUser.RoleName)) { account = new Account(newUser.Email, newUser.Password); } else { account = new Account(newUser.Email, newUser.Password, newUser.UserName, newUser.RoleName); } accountRep.Add(account);//添加新账户 accountRep.PersistAll(); //添加ticket到cookie FormsAuthenticationTicket ticket = AuthenticationHelper.CreateAuthenticationTicket(account.Id.ToString(), account.UserName, true); AuthenticationHelper.SetAuthenticalCookie(ticket); this.InitUserProfile(account.Id); this.InitUserProperty(account.Id); return(account); }
private void GenerarTickectAutenticacion(UsuarioModel usuarioModel) { usuarioModel.TimeZoneId = ConfigurationAppSettings.TimeZoneId(); usuarioModel.TimeZoneGMT = ConfigurationAppSettings.TimeZoneGMT(); AuthenticationHelper.CreateAuthenticationTicket(usuarioModel.Username, usuarioModel.TimeZoneId); WebSession.Usuario = usuarioModel; }
private void GenerarTickectAutenticacion(UsuarioLoginDTO u) { UsuarioModel usuarioModel = new UsuarioModel(); usuarioModel.Username = u.Username; usuarioModel.RolId = u.RolId; usuarioModel.RolNombre = u.RolNombre; usuarioModel.TimeZoneId = ConfigurationAppSettings.TimeZoneId(); usuarioModel.TimeZoneGMT = ConfigurationAppSettings.TimeZoneGMT(); AuthenticationHelper.CreateAuthenticationTicket(usuarioModel.Username, usuarioModel.TimeZoneId); WebSession.Usuario = usuarioModel; WebSession.Formularios = SeguridadBL.Instancia.GetFormulario().Where(p => p.RolId == usuarioModel.RolId); }
/// <summary> /// 初始化用户资料,修改 /// </summary> /// <param name="model">初始化用户资料模型</param> public void ModifyUserProfile(UserProfileModel model) { IRepository <UserProfile> profileRep = Factory.Factory <IRepository <UserProfile> > .GetConcrete <UserProfile>(); UserProfile profile = profileRep.Find(new Specification <UserProfile>(p => p.UserID == model.UserID)); IRepository <Account> acountRep = Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); Account acount = acountRep.Find(new Specification <Account>(p => p.Id == model.UserID)); //修改用户资料 acount.AccountMsgVO = new AccountMessageVO( acount.Id, model.UserName, acount.UserHead, acount.Tiny, acount.Points); profile.Birthday = model.Birthday; profile.Cellphone = model.Cellphone; profile.City = model.City; profile.Company = model.Company; profile.Hobby = model.Hobby; profile.Msn = model.Msn; profile.Province = model.Province; profile.QQ = model.QQ; profile.Sex = model.Sex; profile.Address = model.Address; FormsAuthenticationTicket ticket = AuthenticationHelper.CreateAuthenticationTicket(acount.Id.ToString(), acount.UserName, true); AuthenticationHelper.SetAuthenticalCookie(ticket); profileRep.Update(profile); acountRep.Update(acount); profileRep.PersistAll(); acountRep.PersistAll(); }
private void GenerarTickectAutenticacion(UsuarioDto usuario) { AuthenticationHelper.CreateAuthenticationTicket(usuario.UserName); WebSession.Usuario = usuario; //WebSession.Formularios = _formularioAppService.GetByUsuario(usuario.Id); }
/// <summary> /// 用户登录 /// </summary> /// <param name="name">账户名</param> /// <param name="psd">账户密码</param> /// <returns>Account</returns> public Account Logon(UserLogOnModel model) { Account user = null; //创建账户仓储 IRepository <Account> accountRep = FBS.Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); ISpecification <Account> namespec; if (string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.UserName)) { //昵称登录 namespec = new Specification <Account>(o => o.UserName == model.UserName); } else if (string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Email)) { //邮箱登录 namespec = new Specification <Account>(o => o.Email == model.Email);//查询条件 } else { throw new NullReferenceException("用户登录时,用户名和邮箱至少使用一个"); } if (accountRep.Exists(namespec))//这个账户是否存在 { user = accountRep.Find(namespec); if (!user.CheckPsd(model.Password)) { throw new LogonException("密码错误");//账户存在,密码错误 } else { if (new UserEntryService().CheckForbidden(user.Id)) { throw new LogonException("您由于不遵守相关规定,账户被禁用");//您由于不遵守相关规定,账户被禁用 } //将Identify更新到HttpContext中 UserIdentity u = new UserIdentity("Forms", true, user.Id.ToString()); /*UserInfoService uis=new UserInfoService(); * string[] roles=uis.GetUserRoles(user.Id);*/ string[] roles = user.Roles.Split('|'); if (roles == null) { roles = new string[1] { string.Empty } } ; System.Security.Principal.GenericPrincipal gp = new System.Security.Principal.GenericPrincipal(u, roles); HttpContext.Current.User = gp; //添加ticket到cookie FormsAuthenticationTicket ticket = AuthenticationHelper.CreateAuthenticationTicket(user.Id.ToString(), user.UserName, model.RememberMe); AuthenticationHelper.SetAuthenticalCookie(ticket); } } else { throw new LogonException("账户不存在");//账户不存在 } return(user); }