Exemple #1
0
 public HttpResponseMessage SignIn(LogOnModel model)
 {
     if (ModelState.IsValid)
     {
         var data = UsersService.AuthenticateUser(new AuthenticateUserRequest {
             User = model.UserName, Password = model.Password
         });
         if (data.IsAuthenticated)
         {
             var response = Request.CreateResponse(HttpStatusCode.Created, true);
             FormsAuthentication.SetAuthCookie(model.UserName, false);
             return(response);
         }
         return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "The user name or password provided is incorrect"));
     }
     return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
 }
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var data = UsersService.AuthenticateUser(new AuthenticateUserRequest {
                    User = model.UserName, Password = model.Password
                });
                if (data.IsAuthenticated)
                {
                    return(AuthorizeUserToDomains(data, "", model.RememberMe));
                }
                ModelState.AddModelError("", @"The user name or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form
            return(Json(false));
        }
        public HttpResponseMessage UpdatePassword(string name, string oldp, string newp)
        {
            try
            {
                var data = UsersService.AuthenticateUser(new AuthenticateUserRequest {
                    User = name, Password = oldp
                });
                if (data.IsAuthenticated)
                {
                    UsersService.UpdateUser(new UpdateUserRequest {
                        User = new UserInfo {
                            UserName = name, Password = newp
                        }
                    });
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }

                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Authentication failed"));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }