Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
960 views
in Technique[技术] by (71.8m points)

spartacus storefront - Add "Remember me" checkbox to the login page

How to add to the Login Form new field like "Remember me". Which is not supported out-of-the-box?

Now login form provides just "email" and "password" fields, I extended form with new FormControl remember in ngOnInit method, but I can't pass received value to the auth.authorize method, because this method doesn't expect new value.

import { Component, OnInit } from '@angular/core';
import {FormBuilder, FormControl, Validators} from '@angular/forms';
import {ActivatedRoute} from '@angular/router';
import {AuthRedirectService, AuthService, GlobalMessageService, WindowRef} from '@spartacus/core';

import {CheckoutConfigService, LoginFormComponent} from '@spartacus/storefront';


@Component({
  selector: 'app-app-login-form',
  templateUrl: './app-login-form.component.html',
  styleUrls: ['./app-login-form.component.scss']
})
export class AppLoginFormComponent extends LoginFormComponent implements OnInit {

  constructor(
    auth: AuthService,
    globalMessageService: GlobalMessageService,
    fb: FormBuilder,
    authRedirectService: AuthRedirectService,
    winRef: WindowRef,
    activatedRoute: ActivatedRoute,
    checkoutConfigService: CheckoutConfigService,
  ) {
    super(auth, globalMessageService, fb, authRedirectService, winRef, activatedRoute, checkoutConfigService);

    auth.authorize('email.email.com', '123', true);
  }

  ngOnInit(): void {
    super.ngOnInit();

    this.loginForm.addControl('remember', new FormControl('', Validators.required));
  }
}

enter image description here

Environment: Spartacus 3.0

Screenshot was given from Spartacus 2, but I'm sure you that is the same contract/problem for Spartacus 3.

question from:https://stackoverflow.com/questions/66062114/add-remember-me-checkbox-to-the-login-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Need to override AuthService and add internal variable and then read it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...