Exemplo n.º 1
0
        public void Create(AuthenticationTokenCreateContext context)
        {
            object owinCollection;

            context.OwinContext.Environment.TryGetValue("Microsoft.Owin.Form#collection", out owinCollection);
            var grantType = ((FormCollection)owinCollection)?.GetValues("grant_type").FirstOrDefault();


            var resultIsNull = false;

            if (grantType == null || grantType.Equals("refresh_token"))
            {
                var username = context.Ticket.Identity.FindFirst("sub").Value;
                using (var db = new Data.Entity.HeraEntities())
                {
                    var member = db.Member.FirstOrDefault(x => x.Mobile == username);
                    if (member != null && member.IsApproved)
                    {
                        context.Ticket.Properties.ExpiresUtc = DateTime.Now.AddDays(3);
                        context.SetToken(context.SerializeTicket());
                    }
                    else
                    {
                        resultIsNull = true;
                    }
                }
            }
            else
            {
                context.Ticket.Properties.ExpiresUtc = DateTime.Now.AddDays(3);
                context.SetToken(context.SerializeTicket());
            }
            if (resultIsNull)
            {
                if (context.Ticket.Properties.ExpiresUtc <= DateTime.UtcNow)
                {
                    context.Response.StatusCode   = 401;
                    context.Response.ContentType  = "application/json";
                    context.Response.ReasonPhrase = "unauthorized";
                    return;
                }
            }
        }
Exemplo n.º 2
0
 public GenericRepository(Data.Entity.HeraEntities context)
 {
     _entities = context;
     _dbSet    = context.Set <T>();
 }
Exemplo n.º 3
0
 public UnitOfWork()
 {
     _dbContext = new Data.Entity.HeraEntities();
 }