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)); } }
/// <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); } }
public BaseController() { unitOfWork = new Core.UnitOfWork.UnitOfWork(); messageSource = new Models.MessageSource(); cacheService = new InMemoryCache(); }