Пример #1
0
        void Remove()
        {
            var user = UMC.Security.Identity.Current;
            var act  = Account.Create(user.Id.Value);

            var a    = act[Account.EMAIL_ACCOUNT_KEY];
            var code = Web.UIDialog.AsyncDialog("Remove", d =>
            {
                var fm = new Web.UIFormDialog()
                {
                    Title = "解除验证"
                };
                fm.AddTextValue().Put("邮箱", a.Name);
                fm.AddVerify("验证码", "Code", "您邮箱收到的验证码")
                .Put("Command", "Email").Put("Model", "Account").Put("SendValue", new UMC.Web.WebMeta().Put("Email", a.Name).Put("Code", "Send")).Put("Start", "YES");

                fm.Submit("确认验证码", this.Context.Request, "Email");
                return(fm);
            });
            var session = new UMC.Configuration.Session <Hashtable>(a.Name);

            if (session.Value != null)
            {
                if (String.Equals(session.Value["Code"] as string, code))
                {
                    Account.Post(a.Name, a.user_id, Security.UserFlags.UnVerification, Account.EMAIL_ACCOUNT_KEY);
                    this.Prompt("邮箱解除绑定成功", false);
                    this.Context.Send(new UMC.Web.WebMeta().Put("type", "Email"), true);
                }
            }
            this.Prompt("您输入的验证码错误");
        }
Пример #2
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var strUser = Web.UIDialog.AsyncDialog("Id", d =>
            {
                var dlg      = new UserDialog();
                dlg.IsSearch = true;
                dlg.IsPage   = true;
                if (request.IsMaster)
                {
                    dlg.Menu("创建", "Settings", "User", Guid.Empty.ToString());
                }
                dlg.RefreshEvent = "Setting";
                return(dlg);
            });
            var userId = UMC.Data.Utility.Guid(strUser) ?? Guid.Empty;

            if (request.IsMaster == false)
            {
                this.Prompt("只有管理员才能管理账户");
            }


            var userEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.User>();
            var user       = userEntity.Where.And().Equal(new Data.Entities.User
            {
                Id = userId
            }).Entities.Single() ?? new Data.Entities.User();

            var isAliassetting = false;

            if (userId != Guid.Empty && user.Id.HasValue)
            {
                var setting = Web.UIDialog.AsyncDialog("Setting", d =>
                {
                    var frm   = new Web.UIRadioDialog();
                    frm.Title = "用户操作";
                    frm.Options.Add("部门角色", "Setting");
                    frm.Options.Add("重置密码", "Passwrod");
                    frm.Options.Add("变更别名", "Alias");

                    if (Web.WebServlet.Auths().Count > 0)
                    {
                        frm.Options.Add("功能授权", "Wildcard");
                    }
                    return(frm);
                });
                switch (setting)
                {
                case "Setting":
                    this.Setting(userId);
                    break;

                case "Wildcard":
                    response.Redirect("Settings", "Wildcard", new UMC.Web.WebMeta().Put("Type", "User", "Value", user.Username), true);
                    break;

                case "Alias":
                    isAliassetting = true;
                    break;
                }
            }

            var users = this.AsyncDialog("User", d =>
            {
                var opts = new Web.ListItemCollection();
                var fmDg = new Web.UIFormDialog();
                if (userId == Guid.Empty || user.Id.HasValue == false)
                {
                    fmDg.Title = "添加新账户";

                    fmDg.AddText("账户名", "Username", String.Empty);
                    fmDg.AddText("别名", "Alias", user.Alias);

                    fmDg.AddPassword("密码", "Password", true);
                }
                else
                {
                    if (isAliassetting)
                    {
                        fmDg.Title = "变更别名";
                        opts.Add("登录名", user.Username);
                        fmDg.AddText("新别名", "Alias", user.Alias);
                    }
                    else
                    {
                        fmDg.Title = "重置密码";
                        opts.Add("别名", user.Alias);
                        opts.Add("登录名", user.Username);
                        fmDg.AddTextValue(opts);
                        fmDg.AddPassword("密码", "Password", true);
                    }
                }
                fmDg.Submit("确认提交", request, "Setting");
                return(fmDg);
            });

            if (userId == Guid.Empty || user.Id.HasValue == false)
            {
                if (userId == Guid.Empty)
                {
                    userId = UMC.Security.Membership.Instance().CreateUser(users["Username"].Trim(), users["Password"] ?? Guid.NewGuid().ToString(), users["Alias"]);
                    if (userId == Guid.Empty)
                    {
                        this.Prompt(String.Format("已经存在{0}用户名", users["Username"]));
                    }
                    else
                    {
                        UMC.Security.Membership.Instance().AddRole(users["Username"].Trim(), UMC.Security.Membership.UserRole);
                    }
                }
                else
                {
                    var uid = UMC.Security.Membership.Instance().CreateUser(userId, users["Username"].Trim(), users["Password"] ?? Guid.NewGuid().ToString(), users["Alias"]);
                    if (uid == null)
                    {
                        this.Prompt(String.Format("已经存在{0}用户名", users["Username"]));
                    }
                }


                this.Prompt("账户添加成功", false);

                this.Context.Send(new UMC.Web.WebMeta().Put("type", "Setting"), true);
            }
            else
            {
                if (users.ContainsKey("Password"))
                {
                    UMC.Security.Membership.Instance().Password(user.Username, users["Password"]);
                    this.Prompt(String.Format("{0}的密码已重置", user.Alias));
                }
                else
                {
                    UMC.Security.Membership.Instance().ChangeAlias(user.Username, users["Alias"]);
                    this.Prompt(String.Format("{0}的别名已重置成{1}", user.Username, users["Alias"]));
                }

                this.Context.Send(new UMC.Web.WebMeta().Put("type", "Setting"), true);
            }
        }
Пример #3
0
        void Setting(Guid userId)
        {
            var userEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.User>();
            var user       = userEntity.Where.And().Equal(new Data.Entities.User {
                Id = userId
            }).Entities.Single();
            var userRoleEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.UserToRole>();

            userRoleEntity.Where.And().Equal(new Data.Entities.UserToRole {
                user_id = user.Id
            });
            var roleEntity = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Role>();

            roleEntity.Where.And().Unequal(new Data.Entities.Role {
                Rolename = UMC.Security.Membership.GuestRole
            });
            var userValue = Web.UIFormDialog.AsyncDialog("User", d =>
            {
                var fdlg = new Web.UIFormDialog();
                fdlg.Menu("角色", "Settings", "Role");
                fdlg.Title = String.Format("账户设置", user.Username);

                var opts2 = new Web.ListItemCollection();

                opts2.Add("别名", user.Alias);
                opts2.Add("登录名", user.Username);
                if (user.ActiveTime.HasValue)
                {
                    opts2.Add("最后登录", String.Format("{0:yy-MM-dd HH:mm}", user.ActiveTime));
                }
                if (user.RegistrTime.HasValue)
                {
                    opts2.Add("注册时间", String.Format("{0:yy-MM-dd HH:mm}", user.RegistrTime));
                }

                fdlg.AddTextValue(opts2);
                var flags    = user.Flags ?? UMC.Security.UserFlags.Normal;
                var opts     = new Web.ListItemCollection();
                var selected = ((int)(flags & UMC.Security.UserFlags.Lock)) > 0;
                opts.Add("锁定", "1", selected);
                selected = ((int)(flags & UMC.Security.UserFlags.Disabled)) > 0;
                opts.Add("禁用", "16", selected);
                fdlg.AddCheckBox("状态", "Flags", opts, "0");

                var uRs = new List <UMC.Data.Entities.UserToRole>(userRoleEntity.Query());
                opts    = new Web.ListItemCollection();



                roleEntity.Query(dr =>
                {
                    switch (dr.Rolename)
                    {
                    case UMC.Security.Membership.AdminRole:
                        opts.Add("超级管理员", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    case UMC.Security.Membership.UserRole:
                        opts.Add("内部员工", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    case "TrainAdmin":
                        opts.Add("培训管理员", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;


                    case "StoreManager":
                        opts.Add("店长", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    case "Finance":
                        opts.Add("财务", dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;

                    default:
                        opts.Add(dr.Rolename, dr.Id.ToString(), uRs.Exists(ur => ur.role_id == dr.Id));
                        break;
                    }
                });

                fdlg.AddCheckBox("部门角色", "Roles", opts, "None");
                return(fdlg);
            });
            var Flags = UMC.Security.UserFlags.Normal;

            foreach (var k in userValue["Flags"].Split(','))
            {
                Flags = Flags | UMC.Data.Utility.Parse(k, UMC.Security.UserFlags.Normal);
            }
            userEntity.Update(new Data.Entities.User {
                Flags = Flags, Alias = userValue["Alias"]
            });

            if ((Flags & Security.UserFlags.Disabled) == Security.UserFlags.Disabled)
            {
                UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Session>()
                .Where.And().Equal(new Data.Entities.Session
                {
                    user_id = user.Id
                }).Entities.Delete();
            }

            var rids = new List <Data.Entities.UserToRole>();

            foreach (var k in userValue["Roles"].Split(','))
            {
                switch (k)
                {
                case "None":
                    break;

                default:
                    rids.Add(new Data.Entities.UserToRole {
                        role_id = new Guid(k), user_id = userId
                    });
                    break;
                }
            }
            userRoleEntity.Delete();
            if (rids.Count > 0)
            {
                userRoleEntity.Insert(rids.ToArray());

                UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Session>()
                .Where.And().Equal(new Data.Entities.Session {
                    user_id = userId
                }).Entities.Delete();
            }


            UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Session>()
            .Where.And().Equal(new Data.Entities.Session {
                user_id = userId
            }).Entities.Delete();

            this.Prompt("设置成功");
        }
Пример #4
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var Settings = this.AsyncDialog("Settings", g =>
            {
                if (request.SendValues != null && request.SendValues.ContainsKey("media_id"))
                {
                    return(this.DialogValue(new WebMeta().Put("media_id", request.SendValues["media_id"])));
                }
                var from = new Web.UIFormDialog()
                {
                    Title = this.Title ?? "文本数据导入"
                };

                from.AddFile("选择csv文件", "media_id", String.Empty).Put("Accept", "text/csv");
                from.AddRadio("文件编码", "Encoding").Put("中文操作系统标准(GB2312)", "gb2312").Put("英文操作系统标准(UTF8)", "utf-8", true);
                var opts = from.AddTextValue("必须列名");
                foreach (var s in Columns)
                {
                    opts.Add(s, "必须字段");
                }
                from.Submit("确认上传", request, "Pager");
                return(from);
            });
            var media_id = Settings["media_id"];

            if (media_id.EndsWith(".csv") == false)
            {
                this.Prompt("请上传csv文本文件");
            }

            var Key      = this.AsyncDialog("Key", Utility.Guid(Guid.NewGuid()));
            var pathFile = this.AsyncDialog("File", g =>
            {
                string path2 = UMC.Data.Utility.MapPath(String.Format("App_Data\\Static\\TEMP\\{0}\\", Utility.GetRoot(request.Url)));

                var filename = String.Format("{0}{1}.tmp", path2, Key);
                Utility.Copy(new UMC.Net.HttpClient().GetStreamAsync(media_id).Result, filename);

                return(this.DialogValue(filename));
            });

            if (pathFile.EndsWith(".csv"))
            {
                var pad = new Uri(request.Url, String.Format("/TEMP/{0}", pathFile));
                this.Context.Send(new Web.WebMeta().Put("type", "OpenUrl").Put("value", pad.AbsoluteUri), true);
            }
            var columnSettings = this.AsyncDialog("Columns", g =>
            {
                var reader = new System.IO.StreamReader(pathFile, Encoding.GetEncoding(Settings["Encoding"] ?? "utf-8"));
                var cinex  = 0;
                var from   = new Web.UIFormDialog()
                {
                    Title = "核对字段"
                };
                var csvColumns = CSV.FromCsvLine(CSV.ReadLine(reader));
                reader.Close();
                foreach (var c in this.Columns)
                {
                    var opts = from.AddSelect(c, "Col_" + cinex).Put("请选择", "");
                    for (var i = 0; i < csvColumns.Length; i++)
                    {
                        opts.Add(String.Format("{1}(第{0}列)", i + 1, csvColumns[i]), i.ToString(), String.Equals(csvColumns[i], c, StringComparison.CurrentCultureIgnoreCase));
                    }
                    cinex++;
                }
                from.Submit("确认通过");
                return(from);
            });
            var indexs   = new List <int>();
            var maxIndex = -1;

            for (var i = 0; i < this.Columns.Length; i++)
            {
                var cindex = Convert.ToInt32(columnSettings["Col_" + i]);
                if (maxIndex < cindex)
                {
                    maxIndex = cindex;
                }
                indexs.Add(cindex);
            }
            if (indexs.Count == 0)
            {
                this.Prompt("无有效的字段");
            }

            var userName = Utility.GetUsername();

            var log = new CSV.Log(Utility.GetRoot(request.Url), Key, String.Format("开始{0}", this.Title ?? "文本数据导入"));

            Data.Reflection.Start(() =>
            {
                int rowIndex = 1;
                var reader   = new System.IO.StreamReader(pathFile, Encoding.GetEncoding(Settings["Encoding"] ?? "utf-8"));
                System.IO.FileStream file = System.IO.File.Open(String.Format("{0}.csv", pathFile), System.IO.FileMode.Create);


                try
                {
                    var writer = new System.IO.StreamWriter(file, Encoding.UTF8);
                    var total  = 0;
                    var now    = DateTime.Now;


                    var header = CSV.ReadLine(reader);
                    writer.WriteLine(header);

                    int okindex = 0;

                    CSV.EachRow(reader, data =>
                    {
                        rowIndex++;
                        if (data.Length <= maxIndex)
                        {
                            log.Error(String.Format("第{0}行 数据无效", rowIndex));
                            if (okindex + 10 < rowIndex)
                            {
                                throw new ArgumentException(String.Format("连续超过10条无效的数据"));
                            }
                            return;
                        }
                        var hash = new Hashtable();
                        for (var i = 0; i < indexs.Count; i++)
                        {
                            int index = indexs[i];
                            if (data.Length > index)
                            {
                                if (String.IsNullOrEmpty(data[index]))
                                {
                                    log.Error(String.Format("第{0}行 {1}列数据为空", rowIndex, this.Columns[i]));
                                    if (okindex + 10 < rowIndex)
                                    {
                                        throw new ArgumentException(String.Format("连续超过10条无效的数据"));
                                    }
                                    return;
                                }
                            }
                            else
                            {
                                log.Error(String.Format("第{0}行 无{1}列数据", rowIndex, this.Columns[i]));
                                if (okindex + 10 < rowIndex)
                                {
                                    throw new ArgumentException(String.Format("连续超过10条无效的数据"));
                                }
                                return;
                            }
                            hash[this.Columns[i]] = data[index];
                        }
                        if (Do(log, rowIndex, hash))
                        {
                            total++;
                            okindex = rowIndex;
                        }
                        else
                        {
                            foreach (var d in data)
                            {
                                UMC.Data.CSV.CSVFormat(writer, d);
                                writer.Write(",");
                            }
                            writer.WriteLine();
                            writer.Flush();
                        }
                        if (okindex + 10 < rowIndex)
                        {
                            new ArgumentException(String.Format("连续超过10条无效的数据"));
                        }
                    });
                    writer.Flush();
                    writer.Close();
                    log.End("导入数据完成");
                    log.Info(String.Format("导入成功{0}条", total));
                    log.Info(String.Format("用时{0}", DateTime.Now - now));
                }
                catch (Exception ex)
                {
                    log.End(String.Format("在{0}行导入失败", rowIndex));
                    log.Info(ex.Message);
                }
                finally
                {
                    file.Close();
                    reader.Close();
                    log.Close();
                }
            });    //.Start();

            this.Context.Send(new UISectionBuilder("System", "Log", new WebMeta("Key", Key))
                              .Builder(), true);
        }
Пример #5
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var user = UMC.Security.Identity.Current;
            var act  = Account.Create(user.Id.Value);


            var value = Web.UIDialog.AsyncDialog("Email", d =>
            {
                var acc = act[UMC.Security.Account.EMAIL_ACCOUNT_KEY];
                if (acc != null && (acc.Flags & UserFlags.UnVerification) != UserFlags.UnVerification)
                {
                    return(new Web.UIConfirmDialog("您确认解除与邮箱的绑定吗")
                    {
                        Title = "解除确认", DefaultValue = "Change"
                    });
                }


                var t = new Web.UITextDialog()
                {
                    Title = "邮箱绑定", DefaultValue = acc != null ? acc.Name : ""
                };
                t.Config["submit"] = "下一步";
                return(t);
            });

            switch (value)
            {
            case "Change":

                Remove();
                return;
            }

            if (Data.Utility.IsEmail(value) == false)
            {
                this.Prompt("邮箱格式不正确");
            }


            var entity = Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Account>();

            entity.Where.And().Equal(new UMC.Data.Entities.Account {
                Name = value, Type = Account.EMAIL_ACCOUNT_KEY
            }).And().Unequal(new Data.Entities.Account {
                user_id = user.Id
            });
            if (entity.Count() > 0)
            {
                this.Prompt("此邮箱已存在绑定");
            }


            var Code = UMC.Web.UIDialog.AsyncDialog("Code", g =>
            {
                var fm = new Web.UIFormDialog()
                {
                    Title = "验证码"
                };
                fm.AddTextValue().Put("邮箱", value);
                fm.AddVerify("验证码", "Code", "您邮箱收到的验证码")
                .Put("Command", "Email").Put("Model", "Account").Put("SendValue", new UMC.Web.WebMeta().Put("Email", value).Put("Code", "Send")).Put("Start", "YES");

                fm.Submit("确认验证码", request, "Email");
                return(fm);
            });

            if (Code == "Send")
            {
                this.SendEmail(value);
                this.Prompt("验证码已发送");
            }
            var session = new UMC.Configuration.Session <Hashtable>(value);

            if (session.Value != null)
            {
                var code = session.Value["Code"] as string;
                if (String.Equals(code, Code))
                {
                    Account.Post(value, user.Id.Value, Security.UserFlags.Normal, Account.EMAIL_ACCOUNT_KEY);
                    this.Prompt("邮箱绑定成功", false);
                    this.Context.Send(new UMC.Web.WebMeta().Put("type", "Email"), true);
                }
            }


            this.Prompt("您输入的验证码错误");
        }