Example #1
0
        public static void SignIn(this BzureUser BzureUser, bool RememberMe)
        {
            string TicketData = string.Empty;

            foreach (IContractFactory <ITicketDataService> aspectFactory in TicketDataServiceFactories.Values)
            {
                if (aspectFactory.Build().BuildTicketData(BzureUser, out TicketData))
                {
                    break;//构造成功,必须退出循环
                }
            }

            UserTicket UserTicket = new Principal.UserTicket()
            {
                User       = BzureUser,
                TicketData = TicketData
            };
            FormsAuthenticationTicket ticket =
                new FormsAuthenticationTicket(1, UserTicket.User.UserName,
                                              DateTime.Now, DateTime.Now.AddDays(10),
                                              RememberMe, UserTicket.ToString());

            string     ticketString = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie       = new HttpCookie(FormsAuthentication.FormsCookieName, ticketString);

            if (RememberMe)
            {
                cookie.Expires = DateTime.Now.AddDays(10);
            }

            HttpContext.Current.Response.Cookies.Add(cookie);
        }
Example #2
0
 /// <summary>
 /// 创建新用户
 /// </summary>
 /// <param name="User"></param>
 /// <returns>是否成功</returns>
 public CreateUserResult CreateUser(BzureUser User)
 {
     if (ExistsUserID(User.UserID))
         return CreateUserResult.UserIDExists;
     if (ExistsUserName(User.UserName))
         return CreateUserResult.UserNameExists;
     return new UserRepository(this).CreateUser(User) ? CreateUserResult.Success : CreateUserResult.OtherFailed;
 }
Example #3
0
 /// <summary>
 /// 用户实体数据映射
 /// </summary>
 /// <param name="reader"></param>
 /// <returns></returns>
 public static BzureUser BzureUser_Map(DataReader reader)
 {
     BzureUser BzureUser = new BzureUser(reader.GetString("UserID"), reader.GetString("UserName"))
     {
         EMail = reader.GetStringNullable("EMail"),
         Password = reader.GetStringNullable("Password"),
         OpenID = reader.GetStringNullable("OpenID"),
         State = reader.GetInt("State"),
         RoleValue = reader.GetInt("RoleValue"),
         NickName = reader.GetStringNullable("NickName")
     };
     return BzureUser;
 }
Example #4
0
        static void RegisterFactor_UserState(BizTransaction transaction, BzureUser user)
        {
            IEntityRequestProcess userStateProcessor = Actor.Public.BuildEntityProcessor("SecurityApp");
            TransactionFactor<IEntityRequestProcess, Action<IEntityRequestProcess, EntityPostRequest>> userStateFactor = new TransactionFactor<IEntityRequestProcess, Action<IEntityRequestProcess, EntityPostRequest>>(userStateProcessor);
            userStateFactor.ActionBody = (IEntityRequestProcess contract, EntityPostRequest request) =>
            {
                contract.UpdateEntity(request);
            };

            userStateFactor.Action = (Action<IEntityRequestProcess, EntityPostRequest> action) =>
            {
                EntityPostRequest OrderRequest = BuilderUserStateRequest(user);
                action(userStateProcessor, OrderRequest);
            };

            transaction.RegisterFactor(userStateFactor);
        }
Example #5
0
 public static void AuthorizeUser(this Public Public, BzureUser user, string[] RoleIDs, Action<bool> action)
 {
     string[] oldRoles = Actor.Public.AsRoleManager().GetTeamRoleIDsByUserID(user.UserID.ToString());
     BizTransaction transaction = BizTransaction.BeginTransaction();
     //step 1 修改用户状态
     RegisterFactor_UserState(transaction, user);
     //step 2 删除用户原有的全部角色
     RegisterFactor_DeleteRoles(transaction, user, oldRoles);
     //step 3 添加用户新的角色
     RegisterFactor_AddRoles(transaction, user, RoleIDs);
     bool ok = transaction.TryCommit();
     if (ok)
     {
         Actor.Public.UpdateLastPermissionChangeTime();
     }
     action(ok);
 }
Example #6
0
        static UserRepository()
        {
            BzureUser entity = new BzureUser(string.Empty, string.Empty);
            Type type = entity.GetType();
            AppendDataMap(type, "UserID", () => entity.UserID);
            AppendDataMap(type, "UserName", () => entity.UserName);
            AppendDataMap(type, "Password", () => entity.Password);
            AppendDataMap(type, "State", () => entity.State);
            AppendDataMap(type, "EMail", () => entity.EMail);
            AppendDataMap(type, "OpenID", () => entity.OpenID);
            AppendDataMap(type, "RoleValue", () => entity.RoleValue);
            AppendDataMap(type, "NickName", () => entity.NickName);
            ResultMapDelegate<BzureUser> queryMap = BzureUser_Map;
            QueryMapContainer[entity.GetType()] = queryMap;



        }
Example #7
0
        static EntityPostRequest BuilderUserStateRequest(BzureUser user)
        {
            if (user.IsPersisted())
            {
                EntityPostRequest userStateRequest = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Update)
                {
                    Entity = user
                };
                userStateRequest.AppendFieldMap(user.State, () => user.State);
                userStateRequest.AppendConditionMap(user.UserID, () => user.UserID);
                return userStateRequest;
            }
            else
            {
                throw new Exception(string.Format("用户{0}还没有保存", user.UserName));
            }

        }
Example #8
0
        static void RegisterFactor_DeleteRoles(BizTransaction transaction, BzureUser user, string[] oldRoles)
        {
            IEntityRequestProcess deleteRolesProcessor = Actor.Public.BuildEntityProcessor("SecurityApp");
            TransactionFactor<IEntityRequestProcess, Action<IEntityRequestProcess, EntityPostRequest>> deleteRolesFactor = new TransactionFactor<IEntityRequestProcess, Action<IEntityRequestProcess, EntityPostRequest>>(deleteRolesProcessor);
            deleteRolesFactor.ActionBody = (IEntityRequestProcess contract, EntityPostRequest request) =>
            {
                contract.UpdateEntity(request);
            };

            deleteRolesFactor.Action = (Action<IEntityRequestProcess, EntityPostRequest> action) =>
            {
                foreach (string roleid in oldRoles)
                {
                    EntityPostRequest deleteRoleRequest = BuilddeleteRoleRequest(user.UserID.ToString(), roleid);
                    action(deleteRolesProcessor, deleteRoleRequest);
                }
            };

            transaction.RegisterFactor(deleteRolesFactor);
        }
Example #9
0
 public static UserTicket Build(string TicketValue)
 {
     string[] vs = TicketValue.Split('#');
     UserTicket ut = new UserTicket();
     if (vs.Length > 6)
     {
         BzureUser user = new BzureUser(vs[1], vs[2])
         {
             RoleValue = int.Parse(vs[0]),
             Password = "******",
             State = int.Parse(vs[3]),
             OpenID = vs[4],
             EMail = vs[5],
             NickName = vs[6]
         };
         ut.User = user;
     }
     if (vs.Length > 7)
     {
         ut.TicketData = vs[7];
     }
     return ut;
 }
Example #10
0
        public static UserTicket Build(string TicketValue)
        {
            string[]   vs = TicketValue.Split('#');
            UserTicket ut = new UserTicket();

            if (vs.Length > 6)
            {
                BzureUser user = new BzureUser(vs[1], vs[2])
                {
                    RoleValue = int.Parse(vs[0]),
                    Password  = "******",
                    State     = int.Parse(vs[3]),
                    OpenID    = vs[4],
                    EMail     = vs[5],
                    NickName  = vs[6]
                };
                ut.User = user;
            }
            if (vs.Length > 7)
            {
                ut.TicketData = vs[7];
            }
            return(ut);
        }
Example #11
0
        public ActionResult Register(RegisterModel model)
        {
            IAccountContract ac = Actor.Public.AsAccountManager();
            IUserContract uc = Actor.Public.AsUserManager();
            BzureUser user = new BzureUser(uc.GenerateUserID (), model.UserName)
            {
                EMail = model.Email,
                Password = ac.EncryptPassword(model.Password),
                RoleValue = 0,
                OpenID = string.Empty,
                State = 0,
                NickName = model.UserName
            };
            CreateUserResult result = ac.CreateUser(user);
            if (result == CreateUserResult.Success)
            {
                user.SignIn(false);//登录

                return Redirect("/");
            }
            else
            {
                RegisterViewModel ViewModel = new RegisterViewModel()
                {
                    Title = "注册",
                    Message = result.StringValue(),
                    MasterViewModel = this.MasterViewModel
                };
                return this.Result(ViewModel);

            }

        }
Example #12
0
        /// <summary>
        /// 创建新用户
        /// </summary>
        /// <param name="User"></param>
        /// <returns>是否成功</returns>
        public bool CreateUser(BzureUser User)
        {
            string sql = string.Format("INSERT INTO  {0}(UserID,UserName,Password,State,EMail,OpenID,RoleValue,NickName) VALUES (@UserID, @UserName, @Password, @State, @EMail, @OpenID,@RoleValue,@NickName)", this.TableName);

            int ret = new SqlEntityMap<string>(this.ContractProvider, sql)
                .AddString("UserID", User.UserID)
                .AddString("UserName", User.UserName)
                .AddString("Password", User.Password)
                .AddInt("State", User.State)
                .AddString("EMail", User.EMail)
                .AddString("OpenID", User.OpenID)
                .AddInt("RoleValue", User.RoleValue)
                .AddString("NickName", User.NickName)
                .AsNonQuery();
            if (ret > 0)
                this.MarkPersistenceState(User, true);
            return ret > 0;
        }