Design the auth flow apis (signup, login, etc) for an OTP based user authentication. Assume OTP will be created and presented to users upon a successful login.
- URL
- Request Method
- Request Headers
package grep | |
import ( | |
"os" | |
"path/filepath" | |
"strings" | |
"sync" | |
"testing" | |
"time" | |
) |
package grep | |
import ( | |
"bufio" | |
"flag" | |
"io" | |
"io/ioutil" | |
"log" | |
"os" | |
"path/filepath" |
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
type Command struct { | |
message string | |
senderId int |
package main | |
import ( | |
"io/ioutil" | |
"os" | |
"log" | |
"bufio" | |
"fmt" | |
"strings" | |
"path/filepath" |
var Promise = require("bluebird"); | |
var fileParts = ["http://myfiles.com/file1/part1", | |
"http://myfiles.com/file1/part2", | |
"http://myfiles.com/file1/part3"]; | |
var fetchPart = function(partUrl) { | |
// returns the promise of the part of a file | |
}; | |
var filePartPromises = fileParts.map(fetchPart); |
var Promise = require("bluebird"); | |
var productIds = ["productId1", "productId2", "productId3"]; | |
var getProductsFromDb = function(productId) { | |
// returns a promise of product | |
} | |
var productPromises = productIds.map(getProductFromDb); | |
Promise.all(productPromises).then(function(products) { |
var Promise = require("bluebird"); | |
var apiUrls = ["url1", "url2", "url3"]; | |
var request = function(url) { | |
// request the rate limited api (returns a promise) | |
}; | |
var saveResponse = function(response) { | |
// save response to file/db (returns a promise) | |
}; |
var getUserEmail = function (username) { | |
return userRepository.find(username).then(function (user) { | |
return user.email; | |
}); | |
}; | |
getUserEmail("emma").then(console.log); |
var getUserEmail = function(username) { | |
var deferred = q.defer(); | |
userRepository.find(username) // assume this returns a promise | |
.then(function(user){ | |
deferred.resolve(user.email); | |
}); | |
return deferred.promise; | |
}; | |
getUserEmail("emma").then(console.log); |