Exemplo n.º 1
0
        public LoginResponseModel LoginDemo(LoginTestBindingModel model)
        {
            //Admin admin = new Admin() {Admin_username=model.Username,Admin_pwd=model.Password };
            Admin admin    = _adminLog.GetByUsername(model.Username);
            int   validate = _adminLog.ValidateUser(model);
            ////MockAuthenticationService demoService = new MockAuthenticationService();
            ////Admin user = demoService.GetUser(model.Username, model.Password);
            LoginResponseModel loginresponse = new LoginResponseModel();

            if (validate == 0)
            {
                loginresponse.accesstoken = null;
                loginresponse.Admin_id    = -1;
                loginresponse.success     = false;
                //return N("Username or Password is Incorrect");
                return(loginresponse);//Request.CreateResponse(HttpStatusCode.Unauthorized, "Invalid Username or Password", Configuration.Formatters.JsonFormatter);
            }
            else
            {
                AuthenticationModule authentication = new AuthenticationModule();
                string token = authentication.GenerateTokenForUser(admin.Admin_username, admin.Admin_id);
                //string token = authentication.GenerateTokenForUser(model.sername, admin.Admin_id);
                loginresponse.accesstoken = token;
                loginresponse.Admin_id    = admin.Admin_id;
                loginresponse.success     = true;
                return(loginresponse); //Request.CreateResponse(HttpStatusCode.OK, token, Configuration.Formatters.JsonFormatter);
            }
        }