Commit 35372e38 authored by Arie Peterson's avatar Arie Peterson
Browse files

Merge branch '1-feature-as-a-user-i-can-set-my-profile-settings' into 'master'

Resolve "Feature: As a user I can set my profile settings"

Closes #1

See merge request openappstack/user-panel!6
parents 4b0a23f6 1b603b26
Pipeline #2313 passed with stages
in 3 minutes and 34 seconds
......@@ -16,5 +16,5 @@ fi
echo "Creating application $APPLICATION"
curl --header "Content-Type: application/json" \
--request POST \
--data '{"query": "mutation {createApplication(name: \"'$APPLICATION'\", description: \"'$DESCRIPTION'\"){application{name}}}" }' \
--data '{"query": "mutation {createApplication(name: \"'"$APPLICATION"'\", description: \"'"$DESCRIPTION"'\"){application{name}}}" }' \
$SERVER/graphql
const express = require('express')
const cookieParser = require('cookie-parser')
const bodyParser = require('body-parser')
// Create Express Server that is started by nuxt to process authenticated
// requests on the serverside as a serverMiddleware. Can function as a proxy
......@@ -10,8 +12,9 @@ const app = express()
const auth = require('./middleware/auth')
const isAdmin = require('./middleware/admin')
// Include routes that creare response transmitted to client
// Include routes that create response transmitted to client
const graphql = require('./routes/graphql')
const editUser = require('./routes/user')
// Register authentication middleware
app.use(cookieParser())
......@@ -19,6 +22,8 @@ app.use(auth)
app.use('/admin/', isAdmin)
// Register routes
app.use('/user', bodyParser.json())
app.use('/user', editUser)
app.use('/admin/graphql', graphql)
// Export the server middleware
......
......@@ -8,10 +8,12 @@ const router = Router()
// Proxy all requests going to this route to the API URL.
router.use(function(req, res, next) {
proxy.web(req, res, {
target: API_URL,
ignorePath: true // Don't add a trailing '/'
})
proxy.web(req, res, {
target: API_URL,
ignorePath: true // Don't add a trailing '/'
}, function(error){
console.log(error);
next(error);
});
})
module.exports = router
const nuxtConfig = require('../../nuxt.config')
const API_URL = nuxtConfig.env.BACKEND_API_URL || 'http://localhost:5000/graphql'
const { Router } = require('express')
import OpenAppStackModel from '../model.js'
const router = Router()
router.use(function(req, res, next) {
var backend = new OpenAppStackModel(API_URL);
const username = req.user.name;
if( req.method === 'GET'){
backend.user(username)
.then(
user => res.json(user),
error => next(error));
}
else if( req.method === 'POST'){
var newEmail = req.body.email;
var newPassword = req.body.password;
backend.editUser(username, newEmail, newPassword)
.then(
ok => res.json(ok),
error => next(error));
}
});
module.exports = router
......@@ -13,6 +13,7 @@
<template v-if="$auth.$state.loggedIn">
<b-nav-item-dropdown id="usermenu" :text="$auth.user.name" right>
<b-dropdown-item @click="$auth.logout()">Logout</b-dropdown-item>
<b-dropdown-item to="/profile">Profile</b-dropdown-item>
</b-nav-item-dropdown>
</template>
<template v-else>
......
......@@ -6,9 +6,10 @@
<div class="mt-1">
<template v-if="$auth.$state.loggedIn">
<b-btn class="ml-3" variant="info" to="/oidc">OpenID Connect Info</b-btn>
<b-btn class="ml-3" variant="info" to="/profile">Edit profile</b-btn>
<b-btn id="logoutButton" class="ml-3" variant="danger" @click="$auth.logout()">Logout</b-btn>
</template>
<b-btn id="loginButton" ariant="success" v-else to="/login">
<b-btn id="loginButton" variant="success" v-else to="/login">
Login
</b-btn>
</div>
......
<template>
<div class="container mt-2">
<b-form inline id="profile" @submit='save'>
<label id="username" class="mr-sm-2 large"> {{ $auth.user.name }}</label>
<label class="sr-only" for="password">Password</label>
<b-input
id="password"
type="password"
v-model="user.password"
class="mb-2 mr-sm-2 mb-sm-0"
placeholder="New password"
></b-input>
<label class="sr-only" for="email">Email</label>
<b-input
id="email"
type="email"
class="mb-2 mr-sm-2 mb-sm-0"
v-model="user.email"
></b-input>
</b-input-group>
<b-button class="save" type='submit' variant="primary">Save</b-button>
</b-form>
</div>
</template>
<script>
import axios from 'axios'
export default {
middleware: ['auth'],
methods: {
save: function(evt){
if(evt !== undefined){
// prevent page refresh on submit
evt.preventDefault();
}
axios.post('api/user', this.user)
.then(response => {
this.$bvToast.toast(`Profile successfully updated!`, {
title: 'Update Profile',
autoHideDelay: 5000});
this.user.password = undefined
})
}
},
data() {
return {
user: {
username: this.$auth.user.name,
password: undefined,
email: this.$auth.user.email
}
}
}
}
</script>
......@@ -166,8 +166,6 @@ module.exports = {
.navigate()
.waitForElementVisible('@logoutButton')
.click("@logoutButton")
browser.refresh()
index
.waitForElementVisible('@loginButton')
.click('@loginButton')
login
......
......@@ -27,10 +27,49 @@ module.exports = {
.assert.elementNotPresent("@logoutButton")
.click("@userNameLabel")
.assert.visible("@logoutButton")
.assert.visible("@profileButton")
navbar
.assert.elementPresent('@oidc')
.assert.elementNotPresent('@users')
},
'Change Profile settings' : function (browser) {
const profile = browser.page.profile();
const editProfile = profile.section.editProfile;
const index = browser.page.index();
const navbar = index.section.navbar;
const login = browser.page.login()
const usermenu = navbar.section.usermenu;
const newEmail = "newemail@example.net";
const oldEmail = "oldemail@example.net";
const newPassword = "newPassword";
profile.navigate()
editProfile
.assert.containsText("@username", browser.globals.userUsername)
.clearValue("@email")
.setValue("@email", newEmail)
.setValue('@password', newPassword)
.click("@save")
usermenu.click("@userNameLabel")
.click("@logoutButton")
index.assert.visible('@loginButton')
login.navigate()
.waitForElementVisible('@loginButton')
.click('@loginButton')
.waitForElementVisible('input[name=username]')
.setValue('input[name=username]', browser.globals.userUsername)
.setValue('input[name=password]', newPassword)
.click('input[name=submit]')
index
.waitForElementVisible('@logoutButton')
profile.navigate()
editProfile
.assert.value("@email", newEmail)
editProfile
.clearValue("@email")
.setValue("@email", oldEmail)
.setValue("@password", browser.globals.userPassword)
.submitForm("@password")
},
'Logout' : function (browser) {
const index = browser.page.index();
const navbar = index.section.navbar;
......
......@@ -65,6 +65,10 @@ module.exports = {
userNameLabel:{
selector: '#usermenu'
},
profileButton:{
selector: 'Profile',
locateStrategy: 'link text'
},
logoutButton: {
selector: 'Logout',
locateStrategy: 'link text'
......
module.exports = {
url: function(){
return this.api.launchUrl + "/login"
return this.api.launchUrl + "login"
},
elements: {
loginButton: {
......
module.exports = {
url: function(){
return this.api.launchUrl + "profile"
},
sections: {
editProfile: {
selector: '#profile',
elements: {
username: {
selector: '#username'
},
password: {
selector: '#password'
},
email: {
selector: '#email'
},
save: {
selector: '.btn.save'
}
}
}
}
};
module.exports = {
url: function(){
return this.api.launchUrl + "/users"
return this.api.launchUrl + "users"
},
elements: {},
commands: [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment