typescript/kuzzle + elastic search

커즐(kuzzle) 활용 예시 3(아이디/패스워드 찾기) v5.x

노래하는 마케터 2019. 2. 25. 18:14
728x90
//아이디, 패스워드 찾기 예시입니다.

import { Component, OnInit } from '@angular/core';
import Kuzzle from 'kuzzle-sdk/dist/kuzzle.js';
@Component({
selector: 'app-findidandpwd',
templateUrl: './findidandpwd.page.html',
styleUrls: ['./findidandpwd.page.scss'],
})
export class FindidandpwdPage implements OnInit {

isFindId = true;
findIdName: any;
findIdNickName: any;
findPwdId: any;
findPwdName: any;
findPwdNickName: any;
kuzzle: any;
findIdValue: any;
isFindedIdVal = false;
isFindedPWdVal = false;
temporaryPwd: any;
userPwd: any;

constructor() { }

ngOnInit() {
}

findId() {
this.isFindId = true;
}

findPwd() {
this.isFindId = false;
}
kuzzlefindId() {
const body = {
'query': {
'bool': {
'must': [{
'match': {
'USER_NAME': this.findIdName
}
},
{
'match': {
'USER_NICKNAME': this.findIdNickName
}
}
]
}
}
};
const options = {
from: 0
};

// Using callbacks (NodeJS or Web Browser)
this.kuzzle
.collection('collection_name', 'index_name')
.search(body, options, function (err, searchResult) {
searchResult.getDocuments().forEach(function (document) {
this.findIdValue = document.content.USER_ID;
this.isFindedIdVal = true;
this.findPwdId = this.findIdValue;
}.bind(this));
}.bind(this));
}
kuzzlefindPwd() {
const body = {
'query': {
'bool': {
'must': [{
'match': {
'USER_ID': this.findPwdId
}
},
{
'match': {
'USER_NAME': this.findPwdName
}
},
{
'match': {
'USER_NICKNAME': this.findPwdNickName
}
}
]
}
}
};
const options = {
from: 0
};

// Using callbacks (NodeJS or Web Browser)
this.kuzzle
.collection('collection_name', 'index_name')
.search(body, options, function (err, searchResult) {

searchResult.getDocuments().forEach(function (document) {
this.getRandomPwd();
this.isFindedPwdVal = true;
const id_save = {
'USER_ID': document.content.USER_ID,
'USER_PASSWORD': this.userPwd,
'USER_NAME': document.content.USER_NAME,
'USER_NICKNAME': document.content.USER_NICKNAME
};
this.kuzzle
.collection('emp_user_info', 'name_test')
.updateDocument(this.findPwdId, id_save, function (error, result) {
// result is a Document object
}.bind(this));
}.bind(this));
}.bind(this));
}

getRandomPwd() {
let text = '';
let num = '';
let specialChar = '';
const possibleString = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const possibleNumber = '0123456789';
const possibleSpecialCharacter = '!@#$%';
for ( let i = 0; i < 9; i++ ) {
text += possibleString.charAt(Math.floor(Math.random() * possibleString.length));
}
for ( let i = 0; i < 3; i++ ) {
num += possibleNumber.charAt(Math.floor(Math.random() * possibleNumber.length));
}
for ( let i = 0; i < 1; i++ ) {
specialChar += possibleSpecialCharacter.charAt(Math.floor(Math.random() * possibleSpecialCharacter.
length));
}
this.userPwd = text + specialChar + num;
}
}

//html

<ion-content padding>
<ion-grid class="align-center">
<ion-row style="border: 1px solid #c0c0c0;">
<ion-col style="border-right: 1px solid #c0c0c0;">
<ion-button (click) = "findId()" class="bt" color="btidpwd">아이디 찾기</ion-button>
</ion-col>
<ion-col>
<ion-button (click) = "findPwd()" class="bt" color="btidpwd">비밀번호 찾기</ion-button>
</ion-col>
</ion-row>
<ion-row *ngIf="isFindId === true" style="border-right: 1px solid #c0c0c0;border-left: 1px solid #c0c0c0;
border-bottom: 1px solid #c0c0c0;">
<ion-col>
<ion-list style="background-color: white;">
<ion-item style="margin-left:auto; margin-right: auto; background-color: white;width:80%;height:auto;">
<ion-label style="color:gray">이름</ion-label>
<ion-input type="text" name="findIdName" [(ngModel)]="findIdName"></ion-input>
</ion-item>
<ion-item style="margin-left:auto; margin-right: auto; background-color: white;width:80%;height:auto;">
<ion-label style="color:gray">닉네임</ion-label>
<ion-input type="text" name="findIdNickName" [(ngModel)]="findIdNickName"></ion-input>
</ion-item>
</ion-list>
<ion-button (click) = "kuzzlefindId()" class="bt" color="btidpwd">아이디 찾기</ion-button><br />
<ion-label *ngIf = "isFindedIdVal === true">회원님의 아이디는 {{ findIdValue }}입니다.</ion-label>
</ion-col>
</ion-row>
<ion-row *ngIf="isFindId === false" style="border-right: 1px solid #c0c0c0;border-left: 1px solid #c0c0c0;
border-bottom: 1px solid #c0c0c0;">
<ion-col>
<ion-list style="background-color: white;">
<ion-item style="margin-left:auto; margin-right:auto; background-color:white;width:80%;height:auto;">
<ion-label style="color:gray">이름</ion-label>
<ion-input type="text" name="findPwdName" [(ngModel)]="findPwdName"></ion-input>
</ion-item>
<ion-item style="margin-left:auto; margin-right:auto;background-color:white;width:80%;height:auto;">
<ion-label style="color:gray">아이디</ion-label>
<ion-input type="text" name="findPwdId" [(ngModel)]="findPwdId"></ion-input>
</ion-item>
<ion-item style="margin-left:auto;margin-right:auto;background-color:white;width:80%;height:auto;">
<ion-label style="color:gray">닉네임</ion-label>
<ion-input type="text" name="findPwdNickName" [(ngModel)]="findPwdNickName"></ion-input>
</ion-item>
</ion-list>
<ion-button (click) = "kuzzlefindPwd()" class="bt" color="btidpwd">비밀번호 찾기</ion-button><br />
<ion-input *ngIf="isFindedPwdVal===true" clearInput value="임시 비밀번호는 {{ userPwd }}입니다.">
</ion-input>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>


   


728x90