Add new account setup page

This commit is contained in:
Johannes Zellner
2020-02-05 15:05:34 +01:00
parent 19b5253708
commit 39faf2e55c
3 changed files with 177 additions and 1 deletions

54
src/js/setupaccount.js Normal file
View File

@@ -0,0 +1,54 @@
'use strict';
/* global angular, $ */
// create main application module
var app = angular.module('Application', []);
app.controller('SetupAccountController', ['$scope', '$http', function ($scope, $http) {
// Stupid angular location provider either wants html5 location mode or not, do the query parsing on my own
var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.indexOf('=') === -1 ? [item, true] : [item.slice(0, item.indexOf('=')), item.slice(item.indexOf('=')+1)]; }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {});
var API_ORIGIN = '<%= oauth.apiOrigin %>' || window.location.origin;
$scope.busy = false;
$scope.error = false;
$scope.existingUsername = !!search.username;
$scope.username = search.username || '';
$scope.displayName = '';
$scope.password = '';
$scope.passwordRepeat = '';
$scope.onSubmit = function () {
$scope.busy = true;
var data = {
resetToken: search.resetToken,
email: search.email,
username: $scope.username,
displayName: $scope.displayName,
password: $scope.password
};
function error(status) {
console.log('error', status)
$scope.busy = false;
if (status === 401) $scope.error = 'Invalid reset token';
else if (status === 409) $scope.error = 'Ask your admin for an invite link first';
else $scope.error = 'Unknown error';
}
$http.post(API_ORIGIN + '/api/v1/cloudron/password_reset', data).success(function (data, status) {
if (status !== 202) return error(status);
// set token to autologin
localStorage.token = data.accessToken;
$scope.mode = 'newPasswordDone';
}).error(function (data, status) {
error(status);
});
};
}]);