<commit_before>import { Component } from '@angular/core';
let io = require('socket.io-client');
import { SocketSevice } from '../services/socket.service';
import { UserService } from '../services/user.service';
import { Router, ActivatedRoute, Params } from '@angular/router';


@Component({
  selector: 'login',
  styleUrls: ['login.component.css'],
  // templateUrl: 'login.component.html'
  templateUrl: 'login.component.html'
})

export class LoginComponent {
  // socket = this.socketsevice.socket;
  sexes = ['呵呵', 'a', 'b', '扶她'];
  // tmp = new MyUsers(18, Math.floor(Math.random() * 1000).toString(), this.sexes[3]);
  submiting = false;
  username = '';
  userpassword = '';
  alerts: string = '';
  constructor(
    private router: Router,
    public userService: UserService,
    private socketsevice: SocketSevice) { }



  // async onSubmit() {
  //   this.submiting = true;
  //   let status = await this.socketsevice.start();
  //   if (status) {
  //     console.log('链接服务器成功');
  //
  //     this.socketsevice.login(this.username, this.userpassword);
  //     let timer = setTimeout(() => {
  //       this.submiting = false;
  //       if (this.userService.isLogin) {
  //         console.log('已经登陆');
  //         this.router.navigate(['/room']);
  //       } else {
  //         console.log('计时器登陆失败');
  //       }
  //     }, 2000);
  //     this.socketsevice.loginFail.subscribe(() => {
  //       this.submiting = false;
  //       clearTimeout(timer);
  //       console.log('密码错误');
  //     });
  //
  //   } else {
  //
  //     this.submiting = false;
  //     console.log('链接服务器失败');
  //   }
  // };



  onSubmit() {
    if (strlen(this.username) < 4) {
      this.alerts = '名字太短啦';
      setTimeout(() => this.alerts = '', 3000);
      return;
    }


    console.log('尝试登陆');
    this.submiting = true;
    this.socketsevice.login(this.username, this.userpassword);
    this.socketsevice.loginResult.subscribe((result) => {
      this.submiting = false;
      if (result === '认证成功') {
        console.log('登陆成功');
        this.userService.isLogin = true;
        this.router.navigate(['/room']);
      } else {
        if (result === '认证失败') {
          this.alerts = this.userService.other;
        } else {
          this.alerts = result;
        }
        setTimeout(() => this.alerts = '', 3000);
        // this.socketsevice.disconnect();
        console.log('认证失败');
      }
    });
<commit_msg>限制名字长度<commit_after>import { Component } from '@angular/core';
let io = require('socket.io-client');
import { SocketSevice } from '../services/socket.service';
import { UserService } from '../services/user.service';
import { Router, ActivatedRoute, Params } from '@angular/router';


@Component({
  selector: 'login',
  styleUrls: ['login.component.css'],
  // templateUrl: 'login.component.html'
  templateUrl: 'login.component.html'
})

export class LoginComponent {
  // socket = this.socketsevice.socket;
  sexes = ['呵呵', 'a', 'b', '扶她'];
  // tmp = new MyUsers(18, Math.floor(Math.random() * 1000).toString(), this.sexes[3]);
  submiting = false;
  username = '';
  userpassword = '';
  alerts: string = '';
  constructor(
    private router: Router,
    public userService: UserService,
    private socketsevice: SocketSevice) { }



  // async onSubmit() {
  //   this.submiting = true;
  //   let status = await this.socketsevice.start();
  //   if (status) {
  //     console.log('链接服务器成功');
  //
  //     this.socketsevice.login(this.username, this.userpassword);
  //     let timer = setTimeout(() => {
  //       this.submiting = false;
  //       if (this.userService.isLogin) {
  //         console.log('已经登陆');
  //         this.router.navigate(['/room']);
  //       } else {
  //         console.log('计时器登陆失败');
  //       }
  //     }, 2000);
  //     this.socketsevice.loginFail.subscribe(() => {
  //       this.submiting = false;
  //       clearTimeout(timer);
  //       console.log('密码错误');
  //     });
  //
  //   } else {
  //
  //     this.submiting = false;
  //     console.log('链接服务器失败');
  //   }
  // };



  onSubmit() {
    if (strlen(this.username) < 4) {
      this.alerts = '名字太短啦';
      setTimeout(() => this.alerts = '', 3000);
      return;
    }
    if (strlen(this.username) > 20) {
      this.alerts = '名字太长啦';
      setTimeout(() => this.alerts = '', 3000);
      return;
    }


    console.log('尝试登陆');
    this.submiting = true;
    this.socketsevice.login(this.username, this.userpassword);
    this.socketsevice.loginResult.subscribe((result) => {
      this.submiting = false;
      if (result === '认证成功') {
        console.log('登陆成功');
        this.userService.isLogin = true;
        this.router.navigate(['/room']);
      } else {
        if (result === '认证失败') {
          this.alerts = this.userService.other;
        } else {
          this.alerts = result;
        }
        setTimeout(() => this.alerts = '', 3000);
        // this.socketsevice.disconnect();
        console.log('认证失败');
      }
    });

{'fraction_non_alphanumeric': 0.1836, 'fraction_numerical': 0.0092, 'mean_word_length': 2.205769230769231, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4101246', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1771, 'n_words': 279}