コード例 #1
0
        public ActionResult Save(GlobalConfigModel model)
        {
            helper = new GlobalConfigHelper();

            helper.SetVal("NotificacionesFechaInicioAno", model.NotificacionesFechaInicioAno.ToString());
            helper.SetVal("NotificacionesFechaInicioMes", model.NotificacionesFechaInicioMes.ToString());
            helper.SetVal("NotificacionesMinimoDiasInactividad", model.NotificacionesMinimoDiasInactividad.ToString());

            return(null);
        }
コード例 #2
0
        public void ConfigureAuth(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            // 配置数据库上下文、用户管理器和登录管理器,以便为每个请求使用单个实例
            // app.CreatePerOwinContext(ApplicationDbContext.Create);
            // app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            //app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

            // 使应用程序可以使用 Cookie 来存储已登录用户的信息
            // 并使用 Cookie 来临时存储有关使用第三方登录提供程序登录的用户的信息
            // 配置登录 Cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                //LoginPath = new PathString("/Common/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    // 当用户登录时使应用程序可以验证安全戳。
                    // 这是一项安全功能,当你更改密码或者向帐户添加外部登录名时,将使用此功能。
                    OnValidateIdentity = SecurityStampValidator
                                         .OnValidateIdentity <ApplicationUserManager, User, int>(
                        validateInterval: TimeSpan.FromMinutes(30),
                        regenerateIdentityCallback: (manager, user) =>
                        user.GenerateUserIdentityAsync(manager),
                        getUserIdCallback: (id) => (id.GetUserId <int>()))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

            // 使应用程序可以在双重身份验证过程中验证第二因素时暂时存储用户信息。
            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // 使应用程序可以记住第二登录验证因素,例如电话或电子邮件。
            // 选中此选项后,登录过程中执行的第二个验证步骤将保存到你登录时所在的设备上。
            // 此选项类似于在登录时提供的“记住我”选项。
            app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

            // Configure the application for OAuth based flow
            PublicClientId = "self";
            OAuthOptions   = new OAuthAuthorizationServerOptions
            {
                TokenEndpointPath         = new PathString("/token"),
                Provider                  = new ApplicationOAuthProvider(PublicClientId),
                AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(GlobalConfigHelper.GetSessionTimeOut()),
                //AuthorizeEndpointPath = new PathString(""),
                //AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(1), //TimeSpan.FromDays(7),
                // In production mode set AllowInsecureHttp = false
                AllowInsecureHttp = true
            };

            // Enable the application to use bearer tokens to authenticate users
            app.UseOAuthBearerTokens(OAuthOptions);
        }
コード例 #3
0
        // GET: GlobalConfig
        public ActionResult Index()
        {
            helper = new GlobalConfigHelper();

            var model = new GlobalConfigModel()
            {
                NotificacionesFechaInicioAno        = Convert.ToInt32(helper.GetVal("NotificacionesFechaInicioAno")),
                NotificacionesFechaInicioMes        = Convert.ToInt32(helper.GetVal("NotificacionesFechaInicioMes")),
                NotificacionesMinimoDiasInactividad = Convert.ToInt32(helper.GetVal("NotificacionesMinimoDiasInactividad")),
            };

            return(PartialView(model));
        }
コード例 #4
0
        protected override void Seed(VeccContext context)
        {
            //初始化用户数据 没有数据库时执行一次
            string   salt;
            var      code = UtilityHelper.CreateHashCodePW(GlobalConfigHelper.GetAdminInitialPassword(), out salt);
            SysUsers user = new SysUsers {
                UserName = "******", RoleId = 1, AccountStatus = 3, UserType = 0, CreateDate = DateTime.Now, IsDel = 0, Password = code, Salt = salt
            };

            //角色基础数据
            List <SysRole> sysRoles = new List <SysRole> {
                new SysRole {
                    RoleDescribe = "vecc管理员", RoleName = "admin", IsDel = 0
                },
                new SysRole {
                    RoleDescribe = "sgs检测机构", RoleName = "sgs", IsDel = 0
                },
                new SysRole {
                    RoleDescribe = "engineer工程师", RoleName = "engineer", IsDel = 0
                }
            };

            //基础参数设置
            List <SysParams> sysParams = new List <SysParams> {
                new SysParams {
                    ParamNumber = "001", ParamName = "数据审批状态", ParamType = "pending", ParamValue = 1, IsDel = 0
                },
                new SysParams {
                    ParamNumber = "001", ParamName = "数据审批状态", ParamType = "fail", ParamValue = 2, IsDel = 0
                },
                new SysParams {
                    ParamNumber = "001", ParamName = "数据审批状态", ParamType = "passed", ParamValue = 3, IsDel = 0
                },
                new SysParams {
                    ParamNumber = "002", ParamName = "用户审批状态", ParamType = "pending", ParamValue = 1, IsDel = 0
                },
                new SysParams {
                    ParamNumber = "002", ParamName = "用户审批状态", ParamType = "fail", ParamValue = 2, IsDel = 0
                },
                new SysParams {
                    ParamNumber = "002", ParamName = "用户审批状态", ParamType = "passed", ParamValue = 3, IsDel = 0
                }
            };

            //保存
            context.SysUser.Add(user);
            context.SysRole.AddRange(sysRoles);
            context.SysParams.AddRange(sysParams);
            context.SaveChanges();
        }