Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const baseUrl = 'https://baas.kinvey.com/';
- const appKey = 'kid_BJz94Cj1N';
- const appSecret = 'aa1c91c934994554ae791884e07b2391';
- function makeAuth(type) {
- return type === 'basic'
- ? 'Basic ' + btoa(appKey + ':' + appSecret)
- : 'Kinvey ' + sessionStorage.getItem('authtoken');
- }
- function makeRequest(method, module, url, auth) {
- return req = {
- method,
- url: baseUrl + module + '/' + appKey + '/' + url,
- headers: {
- Authorization: makeAuth(auth)
- }
- };
- }
- function post(module, url, data, auth) {
- let req = makeRequest('POST', module, url, auth);
- req.data = JSON.stringify(data);
- req.headers['Content-Type'] = 'application/json';
- return $.ajax(req);
- }
- async function register() {
- let form = $('#register');
- let username = form.find('input[name="username"]').val();
- let password = form.find('input[name="password"]').val();
- let repeatPass = form.find('input[name="repeatPass"]').val();
- let usernamePattern = /\b[a-zA-Z]{3,}\b/;
- let passwordPattern = /\b[a-zA-Z0-9]{6,}\b/;
- if (!usernamePattern.test(username)) {
- showError('Username should be at least 3 symbols long. Only English letters allowed!');
- } else if (!passwordPattern.test(password)) {
- showError('Password should be at least 6 symbols long. Only English letters and digits allowed!');
- } else if (password !== repeatPass) {
- showError('Passwords do not match!');
- } else {
- try {
- let userInfo = await requester.post('user', '', {username, password},'basic');
- console.log(userInfo); //<---- връща undefined
- saveSession(userInfo);
- showView('carListing');
- showInfo('User registration successful');
- form.find('input[name="username"]').val('');
- form.find('input[name="password"]').val('');
- form.find('input[name="repeatPass"]').val('');
- } catch (err) {
- console.log(err.status)
- handleError(err);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement