public class AuthIn : IUserAuthenticate
    {
        public static ApplicationUserManager UserManager
        {
            get { return HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(); }
        }

        private IAuthenticationManager AuthenticationManager
        {
            get { return HttpContext.Current.GetOwinContext().Authentication; }
        }

        public void CurUserLoginOut()
        {
            AuthenticationManager.SignOut();
        }

        public bool GetUserIsAuthenticated()
        {
            return HttpContext.Current.User.Identity.IsAuthenticated;
        }

        public void SignUserLogin(string strUserName, Dictionary<string, string> extDatas)
        {
            ApplicationUser user = UserManager.FindByName(strUserName);

            if (user == null)
            {
                user = new ApplicationUser { UserName = strUserName, Email = extDatas["Email"] };

                IdentityResult result = Task.Factory.StartNew(s =>
                {
                    return ((ApplicationUserManager)s).CreateAsync(user);
                }, UserManager).Unwrap().GetAwaiter().GetResult();

                if (!result.Succeeded)
                {
                    HttpContext.Current.Response.Write("Error on Create User");
                    return;
                }
            }

            ClaimsIdentity indentiy = Task.Factory.StartNew(s =>
            {
                return user.GenerateUserIdentityAsync(((ApplicationUserManager)s));
            }, UserManager).Unwrap().GetAwaiter().GetResult();

            AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = false }, indentiy);
        }
    }

自定义Mvc5 Owin 验证的更多相关文章

  1. WCF 安全性之 自定义用户名密码验证

    案例下载 http://download.csdn.net/detail/woxpp/4113172 客户端调用代码 通过代理类 代理生成 参见 http://www.cnblogs.com/woxp ...

  2. 【WCF】Silverlight+wcf+自定义用户名密码验证

    本文摘自 http://www.cnblogs.com/virusswb/archive/2010/01/26/1656543.html 在昨天的博文Silverlight3+wcf+在不使用证书的情 ...

  3. jquery.validate.js之自定义表单验证规则

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  4. Spring MVC 项目搭建 -6- spring security 使用自定义Filter实现验证扩展资源验证,使用数据库进行配置

    Spring MVC 项目搭建 -6- spring security使用自定义Filter实现验证扩展url验证,使用数据库进行配置 实现的主要流程 1.创建一个Filter 继承 Abstract ...

  5. Spring-Security 自定义Filter完成验证码校验

    Spring-Security的功能主要是由一堆Filter构成过滤器链来实现,每个Filter都会完成自己的一部分工作.我今天要做的是对UsernamePasswordAuthenticationF ...

  6. ASP.NET Core的JWT的实现(自定义策略形式验证).md

    既然选择了远方,便只顾风雨兼程 __ HANS许 在上篇文章,我们讲了JWT在ASP.NET Core的实现,基于中间件来实现.这种方式有个缺点,就是所有的URL,要嘛需要验证,要嘛不需要验证,没有办 ...

  7. layui 自定义表单验证的几个实例

    *注:使用本方法请先引入layui依赖的layu.js和layui.css 1.html <input type="text" name="costbudget&q ...

  8. 基于struts2框架-自定义身份证号验证器

    自定义拦截器的步骤: 1.定义一个验证器的类: > 自定义的验证器都需要实现 Validator接口.  > 可以选择继承 ValidatorSupport 或 FieldValidato ...

  9. Angular5+ 自定义表单验证器

    Angular5+ 自定义表单验证器 Custom Validators 标签(空格分隔): Angular 首先阐述一下遇到的问题: 怎样实现"再次输入密码"的验证(两个cont ...

随机推荐

  1. (spring-第5回【IoC基础篇】)spring容器从加载配置文件到实例化bean的内部工作机制

    前面讲过,spring的生命周期为:实例化前奏-->实例化-->实例化后期-->初始化前期-->初始化-->初始化后期-->bean的具体调用-->销毁前-- ...

  2. Apache 的启动/重启/停止

    Task: Start Apache 2 Server /启动apache服务 # /etc/init.d/apache2 startor$ sudo /etc/init.d/apache2 star ...

  3. Could not resolve archetype org.apache.maven.archetypes:maven-archetype-webapp:RELEASE from any of the configured repositories.

    修改settings.xml: <mirror> <id>nexus-osc</id> <mirrorOf>*</mirrorOf> < ...

  4. # 20145210 《Java程序设计》第05周学习总结

    教材学习内容总结 第八章 异常处理 8.1语法与继承架构 •使用 try.catch •Java中所有信息都会被打包为对象,如果愿意,可以尝试(try)捕捉(catch)代表错误的对象后做一些处理 • ...

  5. iOS教程

    iOS绘图教程: http://www.cocoachina.com/industry/20140115/7703.html iOS基础教程:--包含脚本 swift http://bbs.zxope ...

  6. 程序退出异常_DebugHeapDelete和std::numpunct

    前几天程序新加一个功能之后,其中用到了boost的lexical_cast<float>,发现在关闭命令行窗口的时候,程序报错,是程序退出清理时候报的错误. 一开始以为是程序新增的功能有问 ...

  7. Ubuntu下安装lamp

    在Ubuntu里安装PHP环境时可以用恨简单的方法,直接用tasksel命令安装. 首先要安装这个命令: sudo apt-get install tasksel 然后,sudo tasksel in ...

  8. 《深入浅出Node.js》第2章 模块机制

    @by Ruth92(转载请注明出处) 第2章 模块机制 JavaScript 先天缺乏的功能:模块. 一.CommonJS 规范: JavaScript 规范的缺陷:1)没有模块系统:2)标准库较少 ...

  9. 实战网卡bond

    一.什么是网卡bond 所谓bond,就是把多个物理网卡绑定成一个逻辑上的网卡,使用同一个IP工作,在增加带宽的同时也可以提高冗余性,一般使用较多的就是来提高冗余,分别和不同交换机相连,提高可靠性,但 ...

  10. 162. Find Peak Element

    A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...