api format, css, auth errors
This commit is contained in:
@@ -22,7 +22,7 @@ angular.module('app.frontend', [
|
||||
RestangularProvider.setDefaultHeaders({"Content-Type": "application/json"});
|
||||
|
||||
var url = apiControllerProvider.defaultServerURL();
|
||||
RestangularProvider.setBaseUrl(url);
|
||||
RestangularProvider.setBaseUrl(url + "/api");
|
||||
|
||||
RestangularProvider.setFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) {
|
||||
var token = localStorage.getItem("jwt");
|
||||
|
||||
@@ -73,9 +73,10 @@ angular.module('app.frontend')
|
||||
this.loginData.status = "Generating Login Keys...";
|
||||
$timeout(function(){
|
||||
apiController.login(this.loginData.email, this.loginData.user_password, function(response){
|
||||
if(response.errors) {
|
||||
console.log("login error", response.errors);
|
||||
this.loginData.status = response.errors[0];
|
||||
if(!response || response.error) {
|
||||
var error = response ? response.error : {message: "An unknown error occured."}
|
||||
this.loginData.status = null;
|
||||
alert(error.message);
|
||||
} else {
|
||||
this.onAuthSuccess(response.user);
|
||||
}
|
||||
@@ -88,8 +89,10 @@ angular.module('app.frontend')
|
||||
|
||||
$timeout(function(){
|
||||
apiController.register(this.loginData.email, this.loginData.user_password, function(response){
|
||||
if(response.errors) {
|
||||
this.loginData.status = response.errors[0];
|
||||
if(!response || response.error) {
|
||||
var error = response ? response.error : {message: "An unknown error occured."}
|
||||
this.loginData.status = null;
|
||||
alert(error.message);
|
||||
} else {
|
||||
this.onAuthSuccess(response.user);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ angular.module('app.frontend')
|
||||
$rootScope.title = "Notes — Standard Notes";
|
||||
onUserSet();
|
||||
} else {
|
||||
$scope.defaultUser = new User(apiController.localUser());
|
||||
$scope.defaultUser = new User(apiController.loadLocalItemsAndUser());
|
||||
onUserSet();
|
||||
}
|
||||
});
|
||||
@@ -141,7 +141,7 @@ angular.module('app.frontend')
|
||||
*/
|
||||
|
||||
$scope.headerLogout = function() {
|
||||
$scope.defaultUser = apiController.localUser();
|
||||
$scope.defaultUser = apiController.loadLocalItemsAndUser();
|
||||
$scope.tags = $scope.defaultUser.tags;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,14 @@ class Item {
|
||||
|
||||
_.merge(this, json_obj);
|
||||
|
||||
if(this.created_at) {
|
||||
this.created_at = new Date(this.created_at);
|
||||
this.updated_at = new Date(this.updated_at);
|
||||
} else {
|
||||
this.created_at = new Date();
|
||||
this.updated_at = new Date();
|
||||
}
|
||||
|
||||
if(!this.uuid) {
|
||||
this.uuid = Neeto.crypto.generateUUID();
|
||||
}
|
||||
@@ -43,6 +51,12 @@ class Item {
|
||||
}
|
||||
}
|
||||
|
||||
static sortItemsByDate(items) {
|
||||
items.sort(function(a,b){
|
||||
return new Date(b.created_at) - new Date(a.created_at);
|
||||
});
|
||||
}
|
||||
|
||||
addReference(reference) {
|
||||
this.content.references.push(reference);
|
||||
this.content.references = _.uniq(this.content.references);
|
||||
|
||||
@@ -62,6 +62,10 @@ angular.module('app.frontend')
|
||||
request.get({email: email}).then(function(response){
|
||||
callback(response.plain());
|
||||
})
|
||||
.catch(function(response){
|
||||
console.log("Error getting current user", response);
|
||||
callback(response.data);
|
||||
})
|
||||
}
|
||||
|
||||
this.getCurrentUser = function(callback) {
|
||||
@@ -77,22 +81,32 @@ angular.module('app.frontend')
|
||||
var user = _.omit(plain, ["items"]);
|
||||
callback(user, items);
|
||||
}.bind(this))
|
||||
.catch(function(error){
|
||||
console.log("Error getting current user", error);
|
||||
callback(null);
|
||||
.catch(function(response){
|
||||
console.log("Error getting current user", response);
|
||||
callback(response.data);
|
||||
})
|
||||
}
|
||||
|
||||
this.login = function(email, password, callback) {
|
||||
this.getAuthParamsForEmail(email, function(authParams){
|
||||
if(!authParams) {
|
||||
callback(null);
|
||||
return;
|
||||
}
|
||||
Neeto.crypto.computeEncryptionKeysForUser(_.merge({email: email, password: password}, authParams), function(keys){
|
||||
this.setMk(keys.mk);
|
||||
var request = Restangular.one("auth/sign_in");
|
||||
request.user = {password: keys.pw, email: email};
|
||||
console.log("sending pw", keys.pw);
|
||||
var params = {password: keys.pw, email: email};
|
||||
_.merge(request, params);
|
||||
request.post().then(function(response){
|
||||
localStorage.setItem("jwt", response.token);
|
||||
callback(response);
|
||||
})
|
||||
.catch(function(response){
|
||||
console.log(response.data);
|
||||
callback(response.data);
|
||||
})
|
||||
}.bind(this));
|
||||
}.bind(this))
|
||||
}
|
||||
@@ -102,16 +116,25 @@ angular.module('app.frontend')
|
||||
this.setMk(keys.mk);
|
||||
keys.mk = null;
|
||||
var request = Restangular.one("auth");
|
||||
request.user = _.merge({password: keys.pw, email: email}, keys);
|
||||
var params = _.merge({password: keys.pw, email: email}, keys);
|
||||
_.merge(request, params);
|
||||
request.post().then(function(response){
|
||||
localStorage.setItem("jwt", response.token);
|
||||
callback(response);
|
||||
})
|
||||
.catch(function(response){
|
||||
console.log(response.data);
|
||||
callback(response.data);
|
||||
})
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
this.changePassword = function(user, current_password, new_password) {
|
||||
this.getAuthParamsForEmail(email, function(authParams){
|
||||
if(!authParams) {
|
||||
callback(null);
|
||||
return;
|
||||
}
|
||||
Neeto.crypto.computeEncryptionKeysForUser(_.merge({password: current_password, email: user.email}, authParams), function(currentKeys) {
|
||||
Neeto.crypto.computeEncryptionKeysForUser(_.merge({password: new_password, email: user.email}, authParams), function(newKeys){
|
||||
var data = {};
|
||||
@@ -122,7 +145,7 @@ angular.module('app.frontend')
|
||||
var user = this.user;
|
||||
|
||||
this._performPasswordChange(currentKeys, newKeys, function(response){
|
||||
if(response && !response.errors) {
|
||||
if(response && !response.error) {
|
||||
// this.showNewPasswordForm = false;
|
||||
// reencrypt data with new mk
|
||||
this.reencryptAllItemsAndSave(user, newKeys.mk, currentKeys.mk, function(success){
|
||||
@@ -149,7 +172,8 @@ angular.module('app.frontend')
|
||||
|
||||
this._performPasswordChange = function(email, current_keys, new_keys, callback) {
|
||||
var request = Restangular.one("auth");
|
||||
request.user = {password: new_keys.pw, password_confirmation: new_keys.pw, current_password: current_keys.pw, email: email};
|
||||
var params = {password: new_keys.pw, password_confirmation: new_keys.pw, current_password: current_keys.pw, email: email};
|
||||
_.merge(request, params);
|
||||
request.patch().then(function(response){
|
||||
callback(response);
|
||||
})
|
||||
@@ -417,10 +441,11 @@ angular.module('app.frontend')
|
||||
localStorage.setItem(key, angular.toJson(value));
|
||||
}
|
||||
|
||||
this.localUser = function() {
|
||||
this.loadLocalItemsAndUser = function() {
|
||||
var user = {};
|
||||
var items = JSON.parse(localStorage.getItem('items'));
|
||||
items = this.mapResponseItemsToLocalModels(items);
|
||||
Item.sortItemsByDate(items);
|
||||
modelManager.items = items;
|
||||
user.items = items;
|
||||
user.shouldMerge = true;
|
||||
|
||||
11
app/assets/javascripts/app/services/filters/appDate.js
Normal file
11
app/assets/javascripts/app/services/filters/appDate.js
Normal file
@@ -0,0 +1,11 @@
|
||||
angular.module('app.frontend')
|
||||
.filter('appDate', function ($filter) {
|
||||
return function (input) {
|
||||
return input ? $filter('date')(new Date(input), 'MM/dd/yyyy', 'UTC') : '';
|
||||
};
|
||||
})
|
||||
.filter('appDateTime', function ($filter) {
|
||||
return function (input) {
|
||||
return input ? $filter('date')(new Date(input), 'MM/dd/yyyy h:mm a') : '';
|
||||
};
|
||||
});
|
||||
@@ -62,9 +62,7 @@ class ModelManager extends ItemManager {
|
||||
|
||||
refreshRelationshipsForTag(tag) {
|
||||
tag.notes = tag.referencesMatchingContentType("Note");
|
||||
tag.notes.sort(function(a,b){
|
||||
return new Date(b.created_at) - new Date(a.created_at);
|
||||
});
|
||||
Item.sortItemsByDate(tag.notes);
|
||||
}
|
||||
|
||||
refreshRelationshipsForNote(note) {
|
||||
|
||||
Reference in New Issue
Block a user