Commit 4bfd4ead authored by Mark Harding's avatar Mark Harding
Browse files

(feat): implements captcha - #646

parent 759cb8aa
Loading
Loading
Loading
Loading
+0 −3
Original line number Original line Diff line number Diff line
@@ -47,7 +47,6 @@ import { ScrollLock } from './directives/scroll-lock';
import { TagsLinks } from './directives/tags';
import { TagsLinks } from './directives/tags';
import { Tooltip } from './directives/tooltip';
import { Tooltip } from './directives/tooltip';
import { MindsAvatar } from './components/avatar/avatar';
import { MindsAvatar } from './components/avatar/avatar';
import { CaptchaComponent } from './components/captcha/captcha.component';
import { Textarea } from './components/editors/textarea.component';
import { Textarea } from './components/editors/textarea.component';
import { TagcloudComponent } from './components/tagcloud/tagcloud.component';
import { TagcloudComponent } from './components/tagcloud/tagcloud.component';
import { DropdownComponent } from './components/dropdown/dropdown.component';
import { DropdownComponent } from './components/dropdown/dropdown.component';
@@ -209,7 +208,6 @@ const routes: Routes = [
    MDL_DIRECTIVES,
    MDL_DIRECTIVES,
    DateSelectorComponent,
    DateSelectorComponent,
    MindsAvatar,
    MindsAvatar,
    CaptchaComponent,
    Textarea,
    Textarea,
    InlineEditorComponent,
    InlineEditorComponent,


@@ -316,7 +314,6 @@ const routes: Routes = [
    MDL_DIRECTIVES,
    MDL_DIRECTIVES,
    DateSelectorComponent,
    DateSelectorComponent,
    MindsAvatar,
    MindsAvatar,
    CaptchaComponent,
    Textarea,
    Textarea,
    InlineEditorComponent,
    InlineEditorComponent,


+0 −11
Original line number Original line Diff line number Diff line
<div class="m-captcha--sum" *ngIf="type == 'sum'">
  <div
    class="m-captcha--sum-question "
    *ngIf="question"
    i18n="A sum (eg. 2 + 2)@@COMMON__CAPTCHA__SIMPLE_SUM"
  >
    What is {{ question[0] }} {{ question[1] }} {{ question[2] }}?
  </div>

  <input type="number" [(ngModel)]="answer" (keyup)="validate()" />
</div>
+0 −23
Original line number Original line Diff line number Diff line
.m-captcha--sum {
  text-align: left;

  .m-captcha--sum-question {
    font-size: 18px;
    padding: 8px;
    letter-spacing: 1px;
    font-family: 'Roboto', Helvetica, sans-serif;
    font-weight: 600;
    display: inline-block;
  }

  input[type='number'] {
    display: inline-block;
    width: 46px;
    font-size: 22px;
    padding: 8px 0px;
    text-align: center;
    font-weight: 600;
    font-family: 'Roboto', Helvetica, sans-serif;
    box-sizing: content-box;
  }
}
+0 −56
Original line number Original line Diff line number Diff line
import { Component, Output, Input, EventEmitter } from '@angular/core';

import { Client } from '../../../services/api';

@Component({
  selector: 'm-captcha',
  templateUrl: 'captcha.component.html',
})
export class CaptchaComponent {
  answer: string | number;
  @Output('answer') emit: EventEmitter<any> = new EventEmitter();
  inProgress: boolean = false;

  type: string = 'sum';
  question: Array<string | number>;
  nonce: number;
  hash: string = '';
  interval;

  constructor(public client: Client) {}

  ngOnInit() {
    this.get();
    this.interval = setInterval(this.get, 1000 * 60 * 4); //refresh every 4 minutes
  }

  ngOnDestroy() {
    clearInterval(this.interval);
  }

  get() {
    this.client.get('api/v1/captcha').then((response: any) => {
      this.type = response.question.type;
      this.question = response.question.question;

      this.nonce = response.question.nonce;
      this.hash = response.question.hash;
    });
  }

  validate() {
    let payload = {
      type: this.type,
      question: this.question,
      answer: this.answer,
      nonce: this.nonce,
      hash: this.hash,
    };
    this.emit.next(JSON.stringify(payload));

    this.client.post('api/v1/captcha', payload).then((response: any) => {
      if (response.success) console.log('success');
      else console.log('error');
    });
  }
}
+0 −1
Original line number Original line Diff line number Diff line
export class CaptchaService {}
Loading