Example #1
0
        /// <summary>
        /// 提交更改,且消除用户contentType类型的Sesion
        /// </summary>
        public void Commit(UMC.Security.Identity id, string contentType)
        {
            this.ContentType = contentType;
            var sessionEneity = UMC.Data.Database.Instance().ObjectEntity <Session>();

            sessionEneity.Where.And().Equal(new Session {
                ContentType = contentType, user_id = id.Id
            });
            sessionEneity.Delete();
            this.Commit(Guid.Empty, id.Id ?? Guid.Empty);
        }
Example #2
0
        static Session GSession(string SessionKey, UMC.Security.Identity user, bool IsIsDefault)
        {
            if (String.IsNullOrEmpty(SessionKey) == false)
            {
                var sessionEneity = UMC.Data.Database.Instance().ObjectEntity <Session>();
                sessionEneity.Where.And(new Session {
                    SessionKey = SessionKey
                });
                //if (user != null)
                //{
                //    if (IsIsDefault)
                //    {
                //        sessionEneity.Where.And().In(new Data.Entities.Session { user_id = user.Id }, Guid.Empty);
                //    }
                //    else
                //    {
                //        sessionEneity.Where.And().Equal(new Data.Entities.Session { user_id = user.Id });//, WebADNuke.Security.Membership.Sharename);
                //    }

                //}
                //else if (IsIsDefault)
                //{
                //    sessionEneity.Where.And().In(new Data.Entities.Session { user_id = Guid.Empty });
                //}

                var sess = sessionEneity.Query(0, 3);
                switch (sess.Length)
                {
                case 0:
                    return(null);

                case 1:
                    return(sess[0]);

                default:
                    if (user == null)
                    {
                        return(sess[0]);
                    }
                    else
                    {
                        if (sess[0].user_id == user.Id)
                        {
                            return(sess[0]);
                        }
                        else
                        {
                            return(sess[1]);
                        }
                    }
                }
            }
            return(null);
        }
Example #3
0
        public Session(string sessionKey, UMC.Security.Identity id)
        {
            this.Key = sessionKey;
            var se = GSession(sessionKey, id, false);

            if (se != null)
            {
                this.ContentType = se.ContentType;

                if (typeof(T) == typeof(string))
                {
                    object obj = se.Content;
                    this.Value = (T)obj;
                }
                else
                {
                    this.Value = UMC.Data.JSON.Deserialize <T>(se.Content);
                }
                _user_id = se.user_id ?? Guid.Empty;
            }
        }
Example #4
0
 public void Commit(T value, UMC.Security.Identity id)
 {
     this.Value = value;
     this.Commit(id, "app/json");
 }
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var type = this.AsyncDialog("type", t => this.DialogValue("auto"));

            switch (type)
            {
            case "wx":
                this.Context.Send(new UMC.Web.WebMeta().Put("type", "login.weixin"), true);
                break;

            case "qq":
                this.Context.Send(new UMC.Web.WebMeta().Put("type", "login.qq"), true);
                break;
            }
            var user = Web.UIFormDialog.AsyncDialog("Login", d =>
            {
                if (request.SendValues != null && request.SendValues.Count > 0)
                {
                    return(this.DialogValue(request.SendValues));
                }
                if (request.Url.Query.Contains("_v=Sub"))
                {
                    this.Context.Send("Login", true);
                }

                //   var u = new UMC.Data.Entities.User { Username = String.Empty };


                var dialog   = new Web.UIFormDialog();
                dialog.Title = "登录";
                switch (type)
                {
                default:
                case "User":
                    this.Context.Send("LoginChange", false);
                    {
                        dialog.AddText("用户名", "Username", String.Empty).Put("placeholder", "用户名/手机/邮箱");

                        dialog.AddPassword("用户密码", "Password", String.Empty);

                        dialog.Submit("登录", request, "User", "LoginChange");
                        var uidesc = new UMC.Web.UI.UIDesc(new WebMeta().Put("eula", "用户协议").Put("private", "隐私政策"));
                        uidesc.Desc("登录即同意“{eula}”和“{private}”");
                        uidesc.Style.AlignCenter();
                        uidesc.Style.Color(0x888).Size(14).Height(34);
                        uidesc.Style.Name("eula").Color(0x3194d0).Click(new UIClick("365lu/provision/eula").Send("Subject", "UIData"));
                        uidesc.Style.Name("private").Color(0x3194d0).Click(new UIClick("365lu/provision/private").Send("Subject", "UIData"));
                        dialog.Add(uidesc);
                        dialog.AddUIIcon("\uf2c1", "免密登录").Command(request.Model, request.Command, "Mobile");
                        dialog.AddUIIcon("\uf1c6", "忘记密码").Put("Model", request.Model).Put("Command", "Forget");
                        dialog.AddUIIcon("\uf234", "注册新用户").Put("Model", request.Model).Put("Command", "Register");
                    }
                    break;

                case "Mobile":
                    this.Context.Send("LoginChange", false);
                    {
                        dialog.AddText("手机号码", "Username", String.Empty).Put("placeholder", "注册的手机号码");

                        dialog.AddVerify("验证码", "VerifyCode", "您收到的验证码").Put("For", "Username").Put("To", "Mobile")
                        .Put("Command", request.Command).Put("Model", request.Model);
                        dialog.Submit("登录", request, "User", "LoginChange");

                        var uidesc = new UMC.Web.UI.UIDesc(new WebMeta().Put("eula", "用户协议").Put("private", "隐私政策"));
                        uidesc.Desc("登录即同意“{eula}”和“{private}”");
                        uidesc.Style.AlignCenter();
                        uidesc.Style.Color(0x888).Size(14).Height(34);
                        uidesc.Style.Name("eula").Color(0x3194d0).Click(new UIClick("365lu/provision/eula").Send("Subject", "UIData"));
                        uidesc.Style.Name("private").Color(0x3194d0).Click(new UIClick("365lu/provision/private").Send("Subject", "UIData"));
                        dialog.Add(uidesc);
                        dialog.AddUIIcon("\uf13e", "密码登录").Command(request.Model, request.Command, "User");
                        dialog.AddUIIcon("\uf234", "注册新用户").Command(request.Model, "Register");    //.Put("Model", request.Model).Put("Command", "Register");
                    }
                    break;
                }

                return(dialog);
            });

            if (user.ContainsKey("Mobile"))
            {
                var mobile = user["Mobile"];

                var account = Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Account>()
                              .Where.And().Equal(new UMC.Data.Entities.Account
                {
                    Name = mobile,
                    Type = UMC.Security.Account.MOBILE_ACCOUNT_KEY
                }).Entities.Single();
                if (account == null)
                {
                    this.Prompt("不存在此账户");
                }


                this.SendMobileCode(mobile);
                this.Prompt("验证码已发送", false);
                this.Context.Send(new UMC.Web.WebMeta().UIEvent("VerifyCode", this.AsyncDialog("UI", "none"), new UMC.Web.WebMeta().Put("text", "验证码已发送")), true);
            }

            var username = user["Username"];

            var userManager = UMC.Security.Membership.Instance();

            if (user.ContainsKey("VerifyCode"))
            {
                var VerifyCode = user["VerifyCode"];
                var session    = new UMC.Configuration.Session <Hashtable>(username);
                if (session.Value != null)
                {
                    var code = session.Value["Code"] as string;
                    if (String.Equals(code, VerifyCode) == false)
                    {
                        this.Prompt("请输入正确的验证码");
                    }
                }
                else
                {
                    this.Prompt("请输入正确的验证码");
                }
                var entity = Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Account>();
                UMC.Data.Entities.Account ac = new UMC.Data.Entities.Account
                {
                    Name = username,
                    Type = UMC.Security.Account.MOBILE_ACCOUNT_KEY
                };

                var eData = entity.Where.And().Equal(ac).Entities.Single();
                if (eData == null)
                {
                    this.Prompt("无此号码关联的账户,请注册");
                }
                else
                {
                    var iden = userManager.Identity(eData.user_id.Value);
                    //System.Security.Principal.IPrincipal p = iden;
                    //if (p.IsInRole(UMC.Security.Membership.UserRole))
                    //{
                    //    this.Prompt("您是内部账户,不可从此入口登录");
                    //}


                    UMC.Security.AccessToken.Login(iden, UMC.Security.AccessToken.Token.Value, request.IsApp ? "App" : "Client", true);
                    this.Context.Send("User", true);
                }
            }
            else
            {
                var passwork = user["Password"];

                var maxTimes = 5;
                UMC.Security.Identity identity = null;
                if (UMC.Data.Utility.IsPhone(username))
                {
                    identity = userManager.Identity(username, Security.Account.MOBILE_ACCOUNT_KEY) ?? userManager.Identity(username);
                }
                else if (username.IndexOf('@') > -1)
                {
                    identity = userManager.Identity(username, Security.Account.EMAIL_ACCOUNT_KEY) ?? userManager.Identity(username);
                }
                else
                {
                    identity = userManager.Identity(username);
                }
                if (identity == null)
                {
                    this.Prompt("用户不存在,请确认用户名");
                }
                var times = userManager.Password(identity.Name, passwork, maxTimes);
                switch (times)
                {
                case 0:
                    var iden = userManager.Identity(username);
                    //System.Security.Principal.IPrincipal p = iden;
                    //if (p.IsInRole(UMC.Security.Membership.UserRole))
                    //{
                    //    this.Prompt("您是内部账户,不可从此入口登录");
                    //}


                    UMC.Security.AccessToken.Login(iden, UMC.Security.AccessToken.Token.Value, request.IsApp ? "App" : "Client", true);


                    this.Context.Send("User", true);



                    break;

                case -2:
                    this.Prompt("您的用户已经锁定,请过后登录");
                    break;

                case -1:
                    this.Prompt("您的用户不存在,请确定用户名");

                    break;

                default:
                    this.Prompt(String.Format("您的用户和密码不正确,您还有{0}次机会", maxTimes - times));

                    break;
                }
            }
        }
Example #6
0
 /// <summary>
 /// 提交更改
 /// </summary>
 public void Commit(UMC.Security.Identity id)
 {
     this.Commit(id.Id ?? Guid.Empty);
 }
        public static void Dashboard(UMC.Security.Identity user, Subject sub)
        {
            var project = Utility.CMS.ObjectEntity <UMC.Data.Entities.Project>()
                          .Where.And().Equal(new Project {
                Id = user.Id
            }).Entities.Single();

            if (project == null)
            {
                var team = new Project();
                team.ModifiedTime = DateTime.Now;


                team.Id           = user.Id;
                team.user_id      = user.Id;
                team.Code         = Utility.Parse36Encode(team.Id.Value.GetHashCode());
                team.CreationTime = DateTime.Now;
                team.Caption      = user.Alias;
                team.Sequence     = 0;
                sub.project_id    = team.Id;


                Utility.CMS.ObjectEntity <UMC.Data.Entities.Project>().Insert(team);
                Data.WebResource.Instance().Transfer(new Uri("https://oss.365lu.cn/UserResources/app/zhishi-icon.jpg"), team.Id.Value, 1);
                var p = new ProjectItem()
                {
                    Id           = Guid.NewGuid(),
                    Caption      = "天天录",
                    Code         = "365lu",
                    CreationTime = DateTime.Now,
                    project_id   = team.Id,
                    Hide         = false,
                    Sequence     = 0,
                    user_id      = user.Id,
                };
                Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectItem>()
                .Insert(p);
                sub.project_item_id = p.Id;

                var portfolio2 = new Portfolio()
                {
                    Id              = Guid.NewGuid(),
                    Caption         = "随笔",
                    Count           = 0,
                    CreationTime    = DateTime.Now,
                    Sequence        = 0,
                    user_id         = user.Id,
                    project_id      = team.Id,
                    project_item_id = p.Id,
                };
                Utility.CMS.ObjectEntity <UMC.Data.Entities.Portfolio>()
                .Insert(portfolio2);
                sub.portfolio_id = portfolio2.Id;
                return;
            }
            var projectItem = Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectItem>()
                              .Where.And().Equal(new ProjectItem {
                project_id = project.Id
            }).Entities.Order.Asc(new ProjectItem {
                Sequence = 0
            })
                              .Entities.Single();

            sub.project_id      = project.Id;
            sub.project_item_id = projectItem.Id;

            var portfolio = Utility.CMS.ObjectEntity <UMC.Data.Entities.Portfolio>()
                            .Where.And().Equal(new Portfolio {
                project_id = project.Id, project_item_id = projectItem.Id
            }).Entities.Order.Asc(new Portfolio {
                Sequence = 0
            })
                            .Entities.Single();

            sub.portfolio_id = portfolio.Id;
        }
Example #8
0
        Project Dashboard(UMC.Security.Identity user)
        {
            var projts = Utility.CMS.ObjectEntity <UMC.Data.Entities.Project>()
                         .Where.And().Equal(new Project {
                user_id = user.Id
            }).Entities.Query(0, 5);

            if (projts.Length == 0)
            {
                var team = new Project();
                team.ModifiedTime = DateTime.Now;


                team.Id           = user.Id;
                team.user_id      = user.Id;
                team.Code         = Utility.Parse36Encode(team.Id.Value.GetHashCode());
                team.CreationTime = DateTime.Now;
                team.Caption      = user.Alias;
                team.Sequence     = 0;

                var strt = UMC.Security.AccessToken.Current.Data["DingTalk-Setting"] as string;//, Utility.Guid(projectId)).Commit();
                if (String.IsNullOrEmpty(strt) == false)
                {
                    var userSetting = Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectUserSetting>()
                                      .Where.And().Equal(new ProjectUserSetting {
                        Id = Utility.Guid(strt, true)
                    }).Entities.Single();

                    if (userSetting != null)
                    {
                        var setting2 = new ProjectSetting()
                        {
                            user_setting_id = userSetting.Id, project_id = team.Id, Type = 11
                        }; Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectSetting>().Insert(setting2);
                    }
                }

                Utility.CMS.ObjectEntity <UMC.Data.Entities.Project>().Insert(team);
                Data.WebResource.Instance().Transfer(new Uri("https://oss.365lu.cn/UserResources/app/zhishi-icon.jpg"), team.Id.Value, 1);
                var p = new ProjectItem()
                {
                    Id           = Guid.NewGuid(),
                    Caption      = "首页",
                    Code         = "Home",
                    CreationTime = DateTime.Now,
                    project_id   = team.Id,
                    Sequence     = 0,
                    user_id      = user.Id,
                };
                Utility.CMS.ObjectEntity <UMC.Data.Entities.ProjectItem>()
                .Insert(p);

                var portfolio = new Portfolio()
                {
                    Id              = Guid.NewGuid(),
                    Caption         = "随笔",
                    Count           = 0,
                    CreationTime    = DateTime.Now,
                    Sequence        = 0,
                    user_id         = user.Id,
                    project_id      = team.Id,
                    project_item_id = p.Id,
                };
                Utility.CMS.ObjectEntity <UMC.Data.Entities.Portfolio>()
                .Insert(portfolio);
                return(team);
            }



            return(new List <Project>(projts).Find(d => d.Id == user.Id) ?? projts[0]);
        }
Example #9
0
        /// <summary>
        /// 登录到线程
        /// </summary>
        /// <param name="id"></param>
        /// <param name="auth"></param>
        /// <returns></returns>
        public virtual UMC.Security.Principal Authorization(Security.AccessToken auth, UMC.Security.Identity id)
        {
            var passDate = Data.Utility.TimeSpan();// DateTime.Now.AddMinutes(-10));

            if (auth.ActiveTime < passDate - 600)
            {
                Data.Reflection.SetProperty(auth, "ActiveTime", passDate);

                this.Activation(auth);
            }
            return(UMC.Security.Principal.Create(id, auth));
        }
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var type = this.AsyncDialog("type", t => this.DialogValue("auto"));

            switch (type)
            {
            case "wx":
                this.Context.Send(new UMC.Web.WebMeta().Put("type", "login.weixin"), true);
                break;

            case "qq":
                this.Context.Send(new UMC.Web.WebMeta().Put("type", "login.qq"), true);
                break;
            }
            var user = Web.UIFormDialog.AsyncDialog("Login", d =>
            {
                var u = new UMC.Data.Entities.User {
                    Username = String.Empty
                };


                var dialog   = new Web.UIFormDialog();
                dialog.Title = "账户登录";
                if (request.IsApp)
                {
                    dialog.AddText("手机号码", "Username", u.Username).Put("placeholder", "手机");

                    dialog.AddVerify("验证码", "VerifyCode", "您收到的验证码").Put("For", "Username").Put("To", "Mobile")
                    .Put("Command", request.Command).Put("Model", request.Model);
                    dialog.Submit("登录", request, "User");
                    dialog.AddUIIcon("\uf234", "注册新用户").Put("Model", request.Model).Put("Command", "Register");
                }
                else
                {
                    dialog.AddText("用户名", "Username", u.Username).Put("placeholder", "手机/邮箱");

                    dialog.AddPassword("用户密码", "Password", String.Empty);
                    dialog.Submit("登录", request, "User");
                    dialog.AddUIIcon("\uf1c6", "忘记密码").Put("Model", request.Model).Put("Command", "Forget");
                    dialog.AddUIIcon("\uf234", "注册新用户").Put("Model", request.Model).Put("Command", "Register");
                }
                return(dialog);
            });

            if (user.ContainsKey("Mobile"))
            {
                var mobile = user["Mobile"];

                var account = Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Account>()
                              .Where.And().Equal(new UMC.Data.Entities.Account
                {
                    Name = mobile,
                    Type = UMC.Security.Account.MOBILE_ACCOUNT_KEY
                }).Entities.Single();
                if (account == null)
                {
                    this.Prompt("不存在此账户");
                }


                this.SendMobileCode(mobile);
                this.Prompt("验证码已发送", false);
                this.Context.Send(new UMC.Web.WebMeta().UIEvent("VerifyCode", this.AsyncDialog("UI", "none"), new UMC.Web.WebMeta().Put("text", "验证码已发送")), true);
            }

            var username = user["Username"];

            var userManager = UMC.Security.Membership.Instance();

            if (user.ContainsKey("VerifyCode"))
            {
                var VerifyCode = user["VerifyCode"];
                var session    = new UMC.Configuration.Session <Hashtable>(username);
                if (session.Value != null)
                {
                    var code = session.Value["Code"] as string;
                    if (String.Equals(code, VerifyCode) == false)
                    {
                        this.Prompt("请输入正确的验证码");
                    }
                }
                else
                {
                    this.Prompt("请输入正确的验证码");
                }
                var entity = Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Account>();
                UMC.Data.Entities.Account ac = new UMC.Data.Entities.Account
                {
                    Name = username,
                    Type = UMC.Security.Account.MOBILE_ACCOUNT_KEY
                };

                var eData = entity.Where.And().Equal(ac).Entities.Single();
                if (eData == null)
                {
                    this.Prompt("无此号码关联的账户,请注册");
                }
                else
                {
                    var iden = userManager.Identity(eData.user_id.Value);
                    System.Security.Principal.IPrincipal p = iden;
                    if (p.IsInRole(UMC.Security.Membership.UserRole))
                    {
                        this.Prompt("您是内部账户,不可从此入口登录");
                    }


                    UMC.Security.AccessToken.Login(iden, UMC.Security.AccessToken.Token.Value, request.IsApp ? "App" : "Client", true);
                    this.Context.Send("User", true);
                }
            }
            else
            {
                var passwork = user["Password"];

                var maxTimes = 5;
                UMC.Security.Identity identity = null;
                if (UMC.Data.Utility.IsPhone(username))
                {
                    identity = userManager.Identity(username, Security.Account.MOBILE_ACCOUNT_KEY) ?? userManager.Identity(username);
                }
                else if (username.IndexOf('@') > -1)
                {
                    identity = userManager.Identity(username, Security.Account.EMAIL_ACCOUNT_KEY) ?? userManager.Identity(username);
                }
                else
                {
                    identity = userManager.Identity(username);
                }
                if (identity == null)
                {
                    this.Prompt("用户不存在,请确认用户名");
                }
                var times = userManager.Password(identity.Name, passwork, maxTimes);
                switch (times)
                {
                case 0:
                    var iden = userManager.Identity(username);
                    System.Security.Principal.IPrincipal p = iden;
                    if (p.IsInRole(UMC.Security.Membership.UserRole))
                    {
                        this.Prompt("您是内部账户,不可从此入口登录");
                    }


                    UMC.Security.AccessToken.Login(iden, UMC.Security.AccessToken.Token.Value, request.IsApp ? "App" : "Client", true);


                    this.Context.Send("User", true);



                    break;

                case -2:
                    this.Prompt("您的用户已经锁定,请过后登录");
                    break;

                case -1:
                    this.Prompt("您的用户不存在,请确定用户名");

                    break;

                default:
                    this.Prompt(String.Format("您的用户和密码不正确,您还有{0}次机会", maxTimes - times));

                    break;
                }
            }
        }
Example #11
0
 /// <summary>
 /// 提交更改,且消除用户contentType类型的Sesion
 /// </summary>
 public void Commit(UMC.Security.Identity id, string contentType)
 {
     this.ContentType = contentType;
     this.Commit(Guid.Empty, id.Id ?? Guid.Empty);
 }