Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 9001 : Tüm alanlar doldurulmalı mesjaı verir.
- // 9002 : Bu mail adresine ait bir kullanıcı zaten var.
- // 9003 : Kayıt yapıldı ve değerler geri dönüldü.
- var userName, mailAddress, password;
- module.exports = {
- post : function(request, response, next) {
- userName = request.body.userName;
- mailAddress = request.body.mailAddress;
- password = request.body.password;
- if( userName === undefined || mailAddress === undefined || password === undefined ){
- sendResult( response, 9001, "Please fill the neccessary fields!" );
- } else {
- request.azureMobile.tables('Users') // Büyük küçük har uyumuna dikkat
- .where({ userMailAddress: mailAddress })
- .read()
- .then( results => onResult( response, request, next, results ) )
- .catch( next ); // it is important to catch any errors and log them
- }
- }
- };
- function onResult(response, request, next, results) {
- if( results.length == 0 ){
- var item = {
- userMailAddress: mailAddress,
- userNameSurname: userName,
- userPassword: password,
- authToken : token(),
- refreshToken : token(),
- tokenExpire : 1440 * 2
- };
- request.azureMobile.tables( 'Users' )
- .insert(item)
- .then( insertResults => sendResult( response, 9003, JSON.stringify( insertResults ) ) )
- .catch(next);
- } else {
- sendResult( response, 9002, "There is exist!" );
- }
- }
- function sendResult( response, status, value ) {
- var result = "{ " +
- "status: " + status +
- ", result: " + value +
- " }";
- response.send( 200, result );
- }
- function token() {
- return "Basic " + rand() + rand(); // to make it longer
- };
- function rand() {
- return Math.random().toString(36).substr(2); // remove `0.`
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement