1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 14:19:43 +02:00
documize/app/app/services/user.js

130 lines
2.7 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
import models from '../utils/model';
export default Ember.Service.extend({
2016-07-26 09:22:50 -07:00
sessionService: Ember.inject.service('session'),
ajax: Ember.inject.service(),
// Adds a new user.
add(user) {
return this.get('ajax').request(`users`, {
type: 'POST',
data: JSON.stringify(user),
contentType: 'json'
}).then(function (response) {
return models.UserModel.create(response);
});
},
// Returns user model for specified user id.
getUser(userId) {
let url = `users/${userId}`;
return this.get('ajax').request(url, {
type: 'GET'
}).then((response) => {
return models.UserModel.create(response);
});
},
// Returns all users for organization.
getAll() {
return this.get('ajax').request(`users`).then((response) => {
return response.map(function (obj) {
return models.UserModel.create(obj);
});
});
},
// Returns all users that can see folder.
getFolderUsers(folderId) {
let url = `users/folder/${folderId}`;
return this.get('ajax').request(url, {
method: "GET"
}).then((response) => {
let data = [];
_.each(response, function (obj) {
data.pushObject(models.UserModel.create(obj));
});
return data;
});
},
// Updates an existing user record.
save(user) {
let userId = user.get('id');
let url = `users/${userId}`;
return this.get('ajax').request(url, {
type: 'PUT',
data: JSON.stringify(user),
contentType: 'json'
});
},
// updatePassword changes the password for the specified user.
updatePassword(userId, password) {
let url = `users/${userId}/password`;
return this.get('ajax').post(url, {
data: password
});
},
// Removes the specified user.
remove(userId) {
let url = `users/${userId}`;
return this.get('ajax').request(url, {
method: 'DELETE'
});
},
// Request password reset.
forgotPassword(email) {
let url = `public/forgot`;
if (is.empty(email)) {
return Ember.RSVP.reject("invalid");
}
let data = JSON.stringify({
email: email
});
return this.get('ajax').request(url, {
method: 'POST',
dataType: 'json',
data: data
});
},
// Set new password.
resetPassword(token, password) {
var url = `public/reset/${token}`;
if (is.empty(token) || is.empty(password)) {
return Ember.RSVP.reject("invalid");
}
return this.get('ajax').request(url, {
method: "POST",
data: password
});
}
});