Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public JsonResult LoginClient(LoginModel model, string returnUrl)
- {
- if (ModelState.IsValid)
- {
- if (((SomethingMembershipProvider)Membership.Provider).ValidateUser(model.UserName, model.Password, ServiceType.Something))
- {
- FormsAuthentication.SetAuthCookie(model.UserName, false);
- return new JsonResult { Data = new { status = "ok" } };
- }
- else
- {
- ModelState.AddModelError("", "Feil brukernavn og/eller passord");
- }
- }
- return new JsonResult();
- }
- username: string;
- password: string;
- constructor(private http: HttpClient, private router: Router) { }
- verificationToken:string;
- ngOnInit() {
- this.onGetTokenClicked(); // I have a button inital for testing
- }
- onLoginClicked(): void {
- let loginHeaders = new HttpHeaders({
- "Content-Type": "application/x-www-form-urlencoded"
- });
- const body = new window.URLSearchParams();
- body.set("UserName", this.username);
- body.set("Password", this.password);
- body.set("__RequestVerificationToken", this.verificationToken);
- this.http.post(`http://localhost:4200/Account/Home/LoginClient`, body.toString(), {
- headers: loginHeaders,
- withCredentials: true
- }).subscribe(s => {
- this.router.navigate(["/"]);
- });
- }
- onGetTokenClicked(): void {
- this.http.get(`http://localhost:4200/Account/Home/Login`, {responseType: "text", withCredentials: true}).subscribe(t => {
- var parser = new DOMParser();
- var xmlDoc = parser.parseFromString(t, "text/html");
- var e:HTMLInputElement = xmlDoc.getElementsByName("__RequestVerificationToken").item(0) as HTMLInputElement;
- this.verificationToken = e.value;
- });
- }
Add Comment
Please, Sign In to add comment