<commit_before>import { Component } from '@angular/core';
import { AuthService } from '../services/auth';
import { Router } from '@angular/router';

@Component({
  selector: 'auth-container',
  styles: [`
     .auth {
       height: 100%;
     }
     input {
       border-bottom: 1px solid lightgrey;
     }
     .ng-invalid.ng-dirty {
       border-bottom: 1px solid red;
     }
     form {
       width: 100%;
       border-radius: 2px;
       background-color: white;
       padding: 20px;
       height: 400px;
     }
     .inputs {
       height: 100%;
       position: relative;
     }
     .link {
       color: lightblue;
     }
     .link:hover {
       background-color: transparent;
     }
     .title {
       font-size: 36px;
       font-weight: 300;
       text-transform: capitalize;
     }
     .error {
       color: red;
       position: absolute;
       right: 20px;
     }
  `],
  template: `
  <div class="auth row center-xs middle-xs">
    <form class="col-xs-6 shadow-2" #authForm="ngForm"
    (submit)="authenticate()">
      <div class="inputs row center-xs middle-xs">
        <h3 class="col-xs-8 title">
          {{ mode }}
        </h3>
        <input
          class="col-xs-8"
          type="email"
          name="email"
          placeholder="email"
          [(ngModel)]="user.email"
          #email="ngModel"
          required
        >
        <div class="error"
        [hidden]="email.valid ||  email.pristine">
          email is invalid
        </div>
        <input
          class="col-xs-8"
          type="password"
          name="password"
          placeholder="password"
          [(ngModel)]="user.password"
          #password="<PASSWORD>"
          required
        >
        <div class="error"
        [hidden]="password.valid || password.pristine">
          password is required
        </div>
        <div class="actions col-xs-12">
          <div class="row center-xs">
            <button type="submit" class="btn-light"
            [disabled]="!authForm.form.valid"
            >
              {{ mode }}
            </button>
            <a class="btn-light link"
            (click)="changeMode()">
               {{ linkText }}
            </a>
          </div>
        </div>
      </div>
    </form>
  </div>
  `
})

export class AuthContainer {

  constructor(
    private router: Router,
    private auth: AuthService,
  ){}

  user = {
    email: '',
    password: ''
  }

  mode: string = 'signin';
  linkText: string = 'Don\'t have an account?';

  changeMode() {
    if(this.mode === 'signin') {
      this.mode = 'singup';
      this.linkText = "Already have an account?";
    } else {
      this.linkText = 'Don\'t have an account?';
      this.mode = 'singin';
    }
  }

  authenticate() {
    this.auth.authenticate(this.mode, this.user)
    .subscribe(() => this.router.navigate(['']));
  }<commit_msg>(chore) refactor auth<commit_after>import { Component } from '@angular/core';
import { AuthService } from '../services/auth';
import { Router } from '@angular/router';

@Component({
  selector: 'auth-container',
  styles: [`
     .auth {
       height: 100%;
     }
     input {
       border-bottom: 1px solid lightgrey;
     }
     .ng-invalid.ng-dirty {
       border-bottom: 1px solid red;
     }
     form {
       width: 100%;
       border-radius: 2px;
       background-color: white;
       padding: 20px;
       height: 400px;
     }
     .inputs {
       height: 100%;
       position: relative;
     }
     .link {
       color: lightblue;
     }
     .link:hover {
       background-color: transparent;
     }
     .title {
       font-size: 36px;
       font-weight: 300;
       text-transform: capitalize;
     }
     .error {
       color: red;
       position: absolute;
       right: 20px;
     }
  `],
  template: `
  <div class="auth row center-xs middle-xs">
    <form class="col-xs-6 shadow-2" #authForm="ngForm"
    (submit)="authenticate()">
      <div class="inputs row center-xs middle-xs">
        <h3 class="col-xs-8 title">
          {{ mode }}
        </h3>
        <input
          class="col-xs-8"
          type="email"
          name="email"
          placeholder="email"
          [(ngModel)]="user.email"
          required
          #email="ngModel"
        >
        <div class="error"
        [hidden]="email.valid ||  email.pristine">
          email is invalid
        </div>
        <input
          class="col-xs-8"
          type="password"
          name="password"
          placeholder="password"
          [(ngModel)]="user.password"
          required
          #password="ngModel"
        >
        <div class="error"
        [hidden]="password.valid || password.pristine">
          password is required
        </div>
        <div class="actions col-xs-12">
          <div class="row center-xs">
            <button type="submit" class="btn-light"
            [disabled]="!authForm.form.valid"
            >
              {{ mode }}
            </button>
            <a class="btn-light link"
            (click)="changeMode()">
               {{ linkText }}
            </a>
          </div>
        </div>
      </div>
    </form>
  </div>
  `
})

export class AuthContainer {
  user = {
    email: '',
    password: ''
  }

  constructor(
    private router: Router,
    private auth: AuthService,
  ){}


  mode: string = 'signin';
  linkText: string = 'Don\'t have an account?';

  changeMode() {
    if (this.mode === 'signin') {
      this.mode = 'singup';
      this.linkText = 'Already have an account?';
    } else {
      this.mode = 'singin';
      this.linkText = 'Don\'t have an account?';
    }
  }

  authenticate() {
    this.auth.authenticate(this.mode, this.user)
    .subscribe(() => this.router.navigate(['']));
  }
{'fraction_non_alphanumeric': 0.14944521497919555, 'fraction_numerical': 0.01144244105409154, 'mean_word_length': 1.6658964879852125, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3365725', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1755, 'n_words': 375}