コード例 #1
0
        public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            using (var unitOfWork = new Core.UnitOfWork.UnitOfWork())
            {
                var userInfo = new LoggedUserInfo {
                    Id = 0, UserName = "******"
                };

                var user = unitOfWork.Repository <Data.Entity.Member>().GetBy(x => x.Mobile == context.UserName && x.Password == context.Password).FirstOrDefault();

                if (user != null)
                {
                    userInfo = new LoggedUserInfo {
                        Id = user.Id, UserName = context.UserName
                    }
                }
                ;


                if (userInfo.Id < 1)
                {
                    context.SetError("invalid_grant", "AuthenticationError");
                }
                else
                {
                    var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                    identity.AddClaim(new Claim("sub", context.UserName));
                    identity.AddClaim(new Claim("role", "user"));
                    context.Validated(identity);
                }
            }
            return(base.GrantResourceOwnerCredentials(context));
        }
    }
コード例 #2
0
ファイル: App.cs プロジェクト: kybelehealth/backend-1.0
 /// <summary>
 /// Getting LanguageId from database by parameter
 /// </summary>
 /// <param name="mobileCode">request device mobile code (tr,en,de vb..)</param>
 /// <returns></returns>
 public static int GetLanguageId(string mobileCode)
 {
     using (var unit = new Core.UnitOfWork.UnitOfWork())
     {
         var lang = unit.Repository <Data.Entity.SLanguage>().GetBy(x => x.MobileCode == mobileCode).FirstOrDefault();
         if (lang == null)
         {
             lang = unit.Repository <Data.Entity.SLanguage>().GetBy(x => x.MobileCode == DEFAULT_LANGUAGE_MOBILE_CODE).FirstOrDefault();
         }
         return(lang.Id);
     }
 }
コード例 #3
0
 public BaseController()
 {
     unitOfWork    = new Core.UnitOfWork.UnitOfWork();
     messageSource = new Models.MessageSource();
     cacheService  = new InMemoryCache();
 }