예제 #1
0
        bool Send(string mobile, UMC.Data.Provider provider)
        {
            var d = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.Account>();

            if (Utility.IsPhone(mobile))
            {
                d.Where.And().Equal(new Data.Entities.Account {
                    Name = mobile, Type = Account.MOBILE_ACCOUNT_KEY
                });
            }
            else
            {
                d.Where.And().Equal(new Data.Entities.Account {
                    Name = mobile, Type = Account.EMAIL_ACCOUNT_KEY
                });
            }
            var acc = d.Single();

            if (acc != null)
            {
                var ac   = Account.Create(acc);
                var user = UMC.Data.Database.Instance().ObjectEntity <UMC.Data.Entities.User>()
                           .Where.And().Equal(new UMC.Data.Entities.User {
                    Id = acc.user_id
                }).Entities.Single();
                var hask = new Hashtable();
                switch (acc.Type)
                {
                case Account.MOBILE_ACCOUNT_KEY:
                    var times = UMC.Data.Utility.IntParse(String.Format("{0}", ac.Items["Times"]), 0) + 1;
                    if (times > 5)
                    {
                        //ac.Items["Date"] = WebADNuke.Utils.Utility.TimeSpan();
                        var date = UMC.Data.Utility.TimeSpan(Data.Utility.IntParse(String.Format("{0}", ac.Items["Date"]), UMC.Data.Utility.TimeSpan()));
                        if (date.AddHours(3) > DateTime.Now)
                        {
                            this.Prompt("您已经超过了5次,请您三小时后再试");
                        }
                        else
                        {
                            times = 0;
                        }
                    }
                    //var code = Utility.NumberCode(Guid.NewGuid().GetHashCode(), 6);
                    ac.Items["Date"]                   = UMC.Data.Utility.TimeSpan();
                    ac.Items["UserHostAddress"]        = this.Context.Request.UserHostAddress;
                    ac.Items[Account.KEY_VERIFY_FIELD] = hask["Code"] = Utility.NumberCode(Guid.NewGuid().GetHashCode(), 6);
                    ac.Commit();
                    //WebADNuke.Data.Reflection.PropertyToDictionary(user, hask);
                    //string body = Utility.Format(provider["Sms"], hask);

                    Net.Message.Instance().Send("Forget", hask, ac.Name);

                    //WebResource.Instance().Send(body, ac.Name);
                    return(true);

                //this.Prompt("短信验证码已经发送,请注意查收");
                //break;
                case Account.EMAIL_ACCOUNT_KEY:

                    ac.Items[Account.KEY_VERIFY_FIELD] = hask["Code"] = Utility.NumberCode(Guid.NewGuid().GetHashCode(), 6);
                    ac.Commit();
                    UMC.Data.Reflection.PropertyToDictionary(user, hask);

                    hask["DateTime"] = DateTime.Now;

                    var mail = new System.Net.Mail.MailMessage();
                    mail.To.Add(mobile);
                    mail.Subject    = Utility.Format(provider["Subject"], hask);
                    mail.Body       = Utility.Format(provider["Body"], hask);
                    mail.IsBodyHtml = true;
                    UMC.Net.Message.Instance().Send(mail);
                    return(true);

                    //this.Prompt("邮箱已经发送,请查收邮箱获取验证码");
                    break;
                }
            }

            return(false);
            //this.Prompt("没有此绑定账户");
        }
예제 #2
0
        public override void ProcessActivity(WebRequest request, WebResponse response)
        {
            var type = this.AsyncDialog("type", g =>
            {
                return(this.DialogValue("SQLite"));

                var fm = new UISheetDialog()
                {
                    Title = "安装数据库"
                };

                //fm.Options.Add(new UIClick("Oracle") { Text = "Oracle数据库" }.Send(request.Model, request.Command));
                //fm.Options.Add(new UIClick("MySql") { Text = "MySql数据库" }.Send(request.Model, request.Command));
                //fm.Options.Add(new UIClick("MSSQL") { Text = "SQL Server数据库" }.Send(request.Model, request.Command));
                fm.Options.Add(new UIClick("SQLite")
                {
                    Text = "SQLite文件数据库"
                }.Send(request.Model, request.Command));
                return(fm);
            });
            var Settings = this.AsyncDialog("Settings", g =>
            {
                var fm = new UIFormDialog()
                {
                    Title = "选择数据库"
                };

                fm.AddText("服务地址", "Server");
                fm.AddText("用户名", "User");
                fm.AddText("密码", "Password");
                fm.AddText("数据库名", "Database");
                switch (type)
                {
                case "SQLite":
                    return(this.DialogValue(new WebMeta().Put("File", "UMC")));

                case "Oracle":
                    fm.AddText("端口", "Port", "1521");
                    fm.AddText("表前缀", "Prefix").Put("tip", "分表设置");
                    fm.Title = "Oracle连接配置";
                    break;

                case "MySql":
                    fm.AddText("端口", "Port", "3306");
                    fm.AddText("表前缀", "Prefix").Put("tip", "分表设置");
                    fm.Title = "MySql连接配置";
                    break;

                case "MSSQL":
                    fm.AddText("端口", "Port", "1433");
                    fm.AddText("表前缀", "Prefix").Put("tip", "分表设置");
                    fm.AddText("拆表符", "Delimiter", "_");
                    fm.Title = "SQL Server连接配置";
                    break;

                default:
                    this.Prompt("数据类型错误");
                    break;
                }
                fm.Submit("确认安装", request, "Initializer");
                return(fm);
            });

            UMC.Data.Provider provder = null;


            switch (type)
            {
            case "SQLite":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.SQLiteDbProvider).FullName);

                var file = Settings["File"];
                if (file.IndexOf('.') == -1)
                {
                    file = file + ".sqlite";
                }
                var path = UMC.Data.Utility.MapPath(String.Format("~App_Data/{0}", file));

                if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(path)))
                {
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(path));
                }
                if (System.IO.File.Exists(path))
                {
                    int i = 1;
                    var m = String.Format("{0}.{1}.bak", path, i);
                    while (System.IO.File.Exists(m))
                    {
                        i++;
                        String.Format("{0}.{1}.bak", path, i);
                    }
                    System.IO.File.Move(path, m);
                }
                provder.Attributes["db"] = file;
                break;

            case "Oracle":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.OracleDbProvider).FullName);
                provder.Attributes["conString"] = Oracle(Settings);
                break;

            case "MySql":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.MySqlDbProvider).FullName);
                provder.Attributes["conString"] = MySQL(Settings);
                break;

            case "MSSQL":
                provder = UMC.Data.Provider.Create("Database", typeof(UMC.Data.Sql.SqlDbProvider).FullName);
                provder.Attributes["conString"] = MSSQL(Settings);
                break;

            default:
                this.Prompt("数据类型错误");
                break;
            }
            if (String.IsNullOrEmpty(Settings["Prefix"]) == false)
            {
                provder.Attributes["delimiter"] = Settings["Delimiter"] ?? "_";
                provder.Attributes["prefix"]    = Settings["Prefix"];
            }
            DbProvider provider = Reflection.CreateObject(provder) as DbProvider;

            DbFactory factory = new DbFactory(provider);

            try
            {
                factory.Open();
                factory.Close();
            }
            catch (Exception ex)
            {
                this.Prompt(ex.Message);
            }

            var Key = Utility.Guid(Guid.NewGuid());
            var log = new UMC.Data.CSV.Log(Utility.GetRoot(request.Url), Key, "开始安装");

            Data.Reflection.Start(() =>
            {
                var Initializers = Data.Sql.Initializer.Initializers();
                try
                {
                    var now      = DateTime.Now;
                    var Names    = new Hashtable();
                    var database = Reflection.Configuration("database") ?? new UMC.Configuration.ProviderConfiguration();
                    var count    = false;
                    foreach (var initer in Initializers)
                    {
                        var dataPro  = database[initer.ProviderName] ?? UMC.Data.Provider.Create(initer.ProviderName, provder.Type);
                        var setupKey = dataPro["setup"] ?? "";
                        if (setupKey.Contains(initer.Name) == false)
                        {
                            count = true;
                            initer.Setup(new Hashtable(), log, provider);
                            initer.Menu(new Hashtable(), new DbFactory(provider));
                            var de = UMC.Data.Provider.Create(initer.ProviderName, provder.Type);
                            de.Attributes.Add(provder.Attributes);
                            de.Attributes["setup"] = String.Format("{0}{1},", setupKey, initer.Name);
                            database.Providers[initer.ProviderName] = de;
                        }
                        else
                        {
                            initer.Check(log, Reflection.CreateObject(dataPro) as DbProvider);
                        }
                    }

                    UMC.Configuration.ProviderConfiguration.Cache.Clear();
                    if (count == false)
                    {
                        log.End("对应组件已经安装");
                    }
                    else
                    {
                        var file = Reflection.AppDataPath("UMC\\database.xml");
                        if (System.IO.File.Exists(file))
                        {
                            int i = 1;
                            var m = Reflection.AppDataPath(String.Format("UMC\\database.xml.{0}.bak", i));
                            while (System.IO.File.Exists(m))
                            {
                                i++;
                                m = Reflection.AppDataPath(String.Format("UMC\\database.xml.{0}.bak", i));
                            }
                            System.IO.File.Move(file, m);
                        }
                        database.WriteTo(file);
                        log.End("安装完成", "默认账户:admin 密码:admin", "请刷新界面");
                        log.Info(String.Format("用时{0}", DateTime.Now - now));
                    }
                }
                catch (Exception ex)
                {
                    log.End("安装失败");
                    log.Info(ex.Message);
                }
                finally
                {
                    log.Close();
                }
            });

            this.Context.Send("Initializer", false);

            response.Redirect("System", "Log", Key);
        }