public UserService(IPrincipal identity, CTX ctx) { _identity = identity; _ctx = ctx; if (identity != null) { User = ctx.DBUsers.Where(x => x.username == identity.Identity.Name).FirstOrDefault<DBUser>(); } }
public static void RegisterComponents(HttpConfiguration config) { var container = new UnityContainer(); // register all your components with the container here // it is NOT necessary to register your controllers CTX ctx = new CTX(); container.RegisterType<IUserController, UserController> ( new HierarchicalLifetimeManager(), new InjectionConstructor(ctx) ); container.RegisterType<IBaseController<Role>, BaseController<Role>> ( new HierarchicalLifetimeManager(), new InjectionConstructor(ctx) ); container.RegisterType<IBaseController<Thing>, BaseController<Thing>> ( new HierarchicalLifetimeManager(), new InjectionConstructor(ctx) ); container.RegisterType<IBaseController<Nav>, BaseController<Nav>> ( new HierarchicalLifetimeManager(), new InjectionConstructor(ctx) ); container.RegisterType<IBaseController<Mapping>, BaseController<Mapping>> ( new HierarchicalLifetimeManager(), new InjectionConstructor(ctx) ); container.RegisterType<IBaseController<ObjectType>, BaseController<ObjectType>> ( new HierarchicalLifetimeManager(), new InjectionConstructor(ctx) ); DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(container)); config.DependencyResolver = new UnityResolver(container);//new Unity.WebApi.UnityDependencyResolver(container); }
public UserController(CTX _ctx) { ctx = _ctx; }
public RefreshTokenService() { _ctx = new CTX(); }
public DBUser IsValidUser(string username, string password) { CTX ctx = new CTX(); DBUser user; Boolean useForms = true; Boolean.TryParse(ConfigurationManager.AppSettings["Forms"], out useForms); if (!useForms) { //if the user name is blank... check for the user from windows auth and pass it. var identity = System.Security.Principal.WindowsIdentity.GetCurrent(); username = identity.Name; user = ctx.DBUsers.Where(x => x.username == username).FirstOrDefault<DBUser>(); if (user == null) { //user auth via windows auth but not in database so add him to db and auth var _User = new DBUser(); _User.authtype = identity.AuthenticationType; _User.username = username; ctx.DBUsers.Add(_User); ctx.SaveChanges(); User = _User; return _User; } else { User = user; return user; } } else { if (username == string.Empty || username == null) { return null; } user = ctx.DBUsers.Where(x => x.username == username).FirstOrDefault<DBUser>(); if (user == null) { return null; } if (HashingService.ValidateHash(user.password, password)) { User = user; return user; } else { return null; } } }