Skip to content
Snippets Groups Projects
Verified Commit 17f7e08d authored by Mark's avatar Mark
Browse files

Refactor create user

parent 9b03be3e
No related branches found
No related tags found
1 merge request!2Minimal frontend
......@@ -85,6 +85,23 @@ export default class OpenAppStackModel {
return roles;
});
}
createUser(username, email, password){
const vars = { username: username, email: email, password: password };
const createUserMutation = `
mutation createUser($username: String!, $email: String!, $password: String!){
createUser(
username: $username,
email: $email,
password: $password
){
user{ username, email }
}
}`;
return this.graphQlClient.query(createUserMutation, vars)
.then( user => {
return user;
});
}
editUser(username, email, password){
const vars = { username: username, email: email, password: password };
const editUserMutation = `
......
......@@ -127,30 +127,19 @@ export default {
}
},
addUser: function(){
const newUser = axios.post(
'/api/admin/graphql', {
query: 'mutation{createUser(username: "' + this.newUser.username + '", password: "'+ this.newUser.password.replace(/"/gi, '\\"') + '", email: "' + this.newUser.email + '"){user{username, email}}}'
}).then((res) => {
if (res.data.errors){
console.log(res.data.errors)
}
else {
var newUser = res.data.data.createUser.user;
var index = this.users.push({
username: newUser.username,
email: newUser.email,
password: undefined,
roles: [],
applications: [],
})
index--;
this.newUser.username = "";
this.newUser.password = undefined
this.newUser.email = "";
this.toggleAddUser()
}
}).catch((e) => {
console.log(e)
backend.createUser(this.newUser.username, this.newUser.email, this.newUser.password)
.then( user => {
this.users.push({
username: this.newUser.username,
email: this.newUser.email,
password: undefined,
roles: [],
applications: []
});
this.newUser.username = "";
this.newUser.password = undefined
this.newUser.email = "";
this.toggleAddUser()
});
},
cancelAddUser: function(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment