From e9a767476663297b2621ed2766d038b20f6f6353 Mon Sep 17 00:00:00 2001 From: MichaelKaiser1 Date: Tue, 9 Mar 2021 19:23:12 +0100 Subject: [PATCH] added captcha to login component --- src/app/app.module.ts | 2 ++ .../onboarding/login/login.component.html | 5 ++-- .../onboarding/login/login.component.ts | 30 +++++++++++++++++-- src/assets/i18n/de.json | 1 + src/assets/i18n/en.json | 1 + src/environments/environment.prod.ts | 5 +++- src/environments/environment.ts | 8 +++-- 7 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 333246c9..653606b3 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -40,6 +40,7 @@ import { ErrorInterceptor } from './interceptors/error.interceptor'; import { ForgotPasswordComponent } from './components/onboarding/forgot-password/forgot-password.component'; import { LanguageMenuComponent } from './components/language-menu/language-menu.component'; import { ProfileComponent } from './components/onboarding/profile/profile.component'; +import {CaptchaModule} from 'primeng/captcha'; registerLocaleData(localeDe, 'de'); @@ -103,6 +104,7 @@ export function tokenGetter(): string | null { progressBar: true, positionClass: 'toast-top-full-width' }), + CaptchaModule, ], providers: [ { diff --git a/src/app/components/onboarding/login/login.component.html b/src/app/components/onboarding/login/login.component.html index 96e0d569..cc03e7e9 100644 --- a/src/app/components/onboarding/login/login.component.html +++ b/src/app/components/onboarding/login/login.component.html @@ -2,7 +2,7 @@

- +

@@ -15,6 +15,7 @@

+

@@ -22,7 +23,7 @@ diff --git a/src/app/components/onboarding/login/login.component.ts b/src/app/components/onboarding/login/login.component.ts index 547fe292..121dc899 100644 --- a/src/app/components/onboarding/login/login.component.ts +++ b/src/app/components/onboarding/login/login.component.ts @@ -1,10 +1,12 @@ +import { environment } from './../../../../environments/environment'; import { SubSink } from 'subsink'; -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy, Renderer2 } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { AuthService } from '../../../services/auth.service'; import { ToastService } from '../../../services/toast.service'; import { LoadingService} from '../../../services/loading.service'; +import { TranslateService } from '@ngx-translate/core'; export const LOCAL_STORAGE_TOKEN_KEY = 'token'; @@ -19,12 +21,18 @@ export class LoginComponent implements OnInit, OnDestroy { loginRequest = false; private subs = new SubSink(); hide = true; + language: string; + captchaSuccess = false; + captchaKey = environment.captcha.key; + script: any; constructor(formBuilder: FormBuilder, private router: Router, private authService: AuthService, private toastService: ToastService, - private loadingService: LoadingService + private loadingService: LoadingService, + private translate: TranslateService, + private renderer: Renderer2 ) { this.loginFormGroup = formBuilder.group({ usernameOrEmail: [null, @@ -44,6 +52,20 @@ export class LoginComponent implements OnInit, OnDestroy { } ngOnInit(): void { + this.translate + .stream('SHORTCUT') + .subscribe(v => this.setLanguage(v)); + this.script = this.renderer.createElement('script'); + this.script = this.renderer.createElement('script'); + this.script.defer = true; + this.script.async = true; + this.script.src = 'https://www.google.com/recaptcha/api.js?render=explicit&onload=loadCaptcha'; + this.renderer.appendChild(document.body, this.script); + } + + setLanguage(param: any) { + this.language = param; + console.log(this.language); } ngOnDestroy(): void { @@ -88,6 +110,10 @@ export class LoginComponent implements OnInit, OnDestroy { }) ); } + + showResponse(response: any) { + this.captchaSuccess = true; + } } diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index dc05fd0f..1f57f037 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -1,4 +1,5 @@ { + "SHORTCUT": "de", "EMAILADDRESS": "E-Mailadresse", "USERNAME": "Benutzername", "GIVENNAME": "Vorname", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 28f2dcaf..ffcd6303 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -1,4 +1,5 @@ { + "SHORTCUT": "en", "EMAILADDRESS": "Email address", "USERNAME": "Username", "GIVENNAME": "Given name", diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index a54fd285..6da9ab64 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,6 +1,9 @@ export const environment = { production: true, - api: { + captcha: { + key: '6Le-g3QaAAAAAJmIN-s37441yuZPBp1M7nqUwtED' + }, + api: { protocol: 'https', baseUrl: 'orso-arpa.azurewebsites.net' }, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 29cbaf69..66bbcdad 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,10 +4,12 @@ export const environment = { production: false, + captcha: { + key: '6Le-g3QaAAAAAJmIN-s37441yuZPBp1M7nqUwtED' + }, api: { - protocol: 'http', - baseUrl: 'localhost:5000' - + protocol: 'https', + baseUrl: 'orso-arpa.azurewebsites.net' }, web: {