示例#1
0
        public HttpResponseMessage Login(string userName, string password)
        {
            Guid userId = _tokenBusinessLogic.Authenticate(userName, password);

            if (userId == Guid.Empty)
            {
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            //return new HttpResponseMessage(HttpStatusCode.Unauthorized);
            return(GetAuthToken(userId));
        }
示例#2
0
        /// <summary>
        /// Protected overriden method for authorizing user
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="actionContext"></param>
        /// <returns></returns>
        protected override bool OnAuthorizeUser(string username, string password, HttpActionContext actionContext)
        {
            //var provider = actionContext.ControllerContext.Configuration
            //                   .DependencyResolver.GetService(typeof(IUserServices)) as IUserServices;
            var provider = new BusinessLogic.TokenBusinessLogic();

            if (provider != null)
            {
                var userId = provider.Authenticate(username, password);
                if (userId != Guid.Empty)
                {
                    var basicAuthenticationIdentity = Thread.CurrentPrincipal.Identity as BasicAuthenticationIdentity;
                    if (basicAuthenticationIdentity != null)
                    {
                        basicAuthenticationIdentity.UserId = userId;
                    }
                    return(true);
                }
            }
            return(false);
        }