Skip to content

Instantly share code, notes, and snippets.

@olkunmustafa
Created August 29, 2016 14:31
Show Gist options
  • Save olkunmustafa/c75f2b0614db871c6220a6684c84f7c1 to your computer and use it in GitHub Desktop.
Save olkunmustafa/c75f2b0614db871c6220a6684c84f7c1 to your computer and use it in GitHub Desktop.
// 9001 : Tüm alanlar doldurulmalı mesjaı verir.
// 9004 : Bu mail adresine ait bir kullanıcı yok!
// 9005 : Mail adresine ait kayıt geri dönüldü!
var mailAddress, userPass;
module.exports = {
get : function(request, response, next) {
mailAddress = request.query.mailAddress;
userPass = request.query.password;
if( mailAddress === undefined || userPass === undefined ){
sendResult( response, 9001, "Please fill the neccessary fields!" );
} else {
request.azureMobile.tables('Users') // Büyük küçük harf uyumuna dikkat
.where({ userMailAddress: mailAddress })
.where({ userPassword : userPass })
.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 ){
sendResult( response, 9005, JSON.stringify( results ) );
} else {
sendResult( response, 9004, "There is no 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.`
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment