Created
April 23, 2014 09:39
-
-
Save b1ff/11208819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AllowAnonymous] | |
public class AuthenticationController: ApiController | |
{ | |
private readonly IFormsAuthWrapper _formsAuth; | |
public AuthenticationController(IFormsAuthWrapper formsAuth) | |
{ | |
_formsAuth = formsAuth; | |
} | |
public HttpResponseMessage Token([FromBody]TokenRequest tokenRequest) | |
{ | |
if (tokenRequest == null) | |
{ | |
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot parse input parameters"); | |
} | |
if (Membership.ValidateUser(tokenRequest.Username, tokenRequest.Password)) | |
{ | |
return Request.CreateResponse(HttpStatusCode.Created, new TokenResult | |
{ | |
Success = true, | |
Token = _formsAuth.GetAuthToken(tokenRequest.Username, tokenRequest.Persist) | |
}); | |
} | |
return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Wrong username or password"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment