123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- <template>
- <div id='app'>
- <modal-window v-model='showAjaxErrorsModal' style='z-index: 100' width='auto'>
- <div style='padding: 0rem 1rem 1rem 1rem;'>
- <p v-for='error in this.$store.state.ajaxErrors'>{{error}}</p>
- <button class='button' @click='showAjaxErrorsModal = false'>OK</button>
- </div>
- </modal-window>
- <modal-window v-model='showAccountModal'>
- <tab-view :tabs='["Sign up", "Login"]' v-model="showAccountTab" padding='true'>
- <template slot='Sign up'>
- <p style='margin-top: 0;'>
- Sign up to create and post in threads.
- <br/>It only takes a few seconds
- </p>
- <fancy-input
- v-model='signup.username'
- :error='signup.errors.username'
- placeholder='Username'
- width='100%'
- >
- </fancy-input>
- <fancy-input
- v-model='signup.password'
- :error='signup.errors.password'
- placeholder='Password'
- type='password'
- width='100%'
- >
- </fancy-input>
- <fancy-input
- v-model='signup.confirmPassword'
- :error='signup.errors.confirmPassword'
- placeholder='Confirm password'
- type='password'
- width='100%'
- >
- </fancy-input>
- <loading-button class='button--green' :loading='signup.loading' @click='createAccount'>
- Sign up
- </loading-button>
- <button class='button' @click='closeAccountModal'>
- Cancel
- </button>
- </template>
- <template slot='Login'>
- <p style='margin-top: 0;'>
- Login to create and post in threads.
- </p>
- <fancy-input
- v-model='login.username'
- :error='login.errors.username'
- placeholder='Username'
- width='100%'
- >
- </fancy-input>
- <fancy-input
- v-model='login.password'
- :error='login.errors.password'
- placeholder='Password'
- type='password'
- width='100%'
- >
- </fancy-input>
- <loading-button class='button button--green' :loading='login.loading' @click='doLogin'>
- Log in
- </loading-button>
- <button class='button' @click='closeAccountModal'>
- Cancel
- </button>
- </template>
- </tab-view>
- </modal-window>
- <header class='header'>
- <div class='header__group'>
- <div class='logo' @click='$router.push("/")'>{{name}}</div>
- </div>
- <div class='header__group'>
- <template v-if='$store.state.username'>
- <loading-button @click='logout' :loading='loadingLogout'>
- Log out
- </loading-button>
- </template>
- <template v-else>
- <div class='button button--green' @click='showAccountModalTab(0)'>
- Sign up
- </div>
- <div class='button' @click='showAccountModalTab(1)'>
- Login
- </div>
- </template>
- <div class='search' tabindex='0'>
- <input class='search__field' placeholder='Search this forum'>
- <button class='button button--borderless'><span class='fa fa-search'></span></button>
- </div>
- </div>
- </header>
- <router-view></router-view>
- </div>
- </template>
- <script>
- import ModalWindow from './components/ModalWindow'
- import TabView from './components/TabView'
- import FancyInput from './components/FancyInput'
- import LoadingButton from './components/LoadingButton'
- import mapGetters from 'vuex'
- import AjaxErrorHandler from './assets/js/errorHandler'
- export default {
- name: 'app',
- components: {
- ModalWindow,
- TabView,
- FancyInput,
- LoadingButton
- },
- data () {
- return {
- signup: {
- username: '',
- password: '',
- confirmPassword: '',
- loading: false,
- errors: {
- username: '',
- password: '',
- confirmPassword: ''
- }
- },
- login: {
- username: '',
- password: '',
- loading: false,
- errors: {
- username: '',
- password: ''
- }
- },
- loadingLogout: false,
- ajaxErrorHandler: AjaxErrorHandler(this.$store)
- }
- },
- computed: {
- name () {
- return this.$store.state.meta.name
- },
- showAccountModal: {
- get () { return this.$store.state.accountModal },
- set (val) {
- this.$store.commit('setAccountModalState', val);
- }
- },
- showAjaxErrorsModal: {
- get () { return this.$store.state.ajaxErrorsModal },
- set (val) { this.$store.commit('setAjaxErrorsModalState', val) }
- },
- showAccountTab : {
- get (val) { return this.$store.state.accountTabs },
- set (index) { this.$store.commit('setAccountTabs', index) }
- }
- },
- methods: {
- showAccountModalTab (index) {
- this.showAccountModal = true
- this.showAccountTab = index
- },
- logout () {
- this.loadingLogout = true
- this.axios.post(
- '/api/v1/user/' +
- this.$store.state.username +
- '/logout'
- ).then(res => {
- this.loadingLogout = false
- this.$store.commit('setUsername', '')
- }).catch(err => {
- this.loadingLogout = false
- this.ajaxErrorHandler(err)
- })
- },
- clearSignup () {
- this.signup.username = ''
- this.signup.password = ''
- this.signup.confirmPassword = ''
- },
- clearSignupErrors () {
- this.signup.errors.username = ''
- this.signup.errors.password = ''
- this.signup.errors.confirmPassword = ''
- },
- clearLogin () {
- this.login.username = ''
- this.login.password = ''
- },
- clearLoginErrors () {
- this.login.errors.username = ''
- this.login.errors.password = ''
- },
- closeAccountModal () {
- this.showAccountModal = false
- this.clearLogin()
- this.clearSignup()
- this.clearLoginErrors()
- this.clearSignupErrors()
- },
- createAccount () {
- this.clearSignupErrors()
- if(this.signup.password !== this.signup.confirmPassword) {
- this.signup.errors.confirmPassword = 'Passwords must match'
- } else {
- this.signup.loading = true
- this.axios.post('/api/v1/user', {
- username: this.signup.username,
- password: this.signup.password
- }).then(res => {
- this.signup.loading = false
- this.$store.commit('setUsername', res.data.username)
- this.closeAccountModal()
- }).catch(e => {
- this.signup.loading = false
- this.ajaxErrorHandler(e, (error) => {
- let param = error.parameter
- if(this.signup.errors[param] !== undefined) {
- this.signup.errors[param] = error.message
- }
- })
- })
- }
- },
- doLogin () {
- this.clearSignupErrors()
- if(!this.login.username.trim().length) {
- this.login.errors.username = 'Username must not be blank'
- return
- }
- this.login.loading = true
- this.axios.post(`/api/v1/user/${this.login.username}/login`, {
- password: this.login.password
- }).then(res => {
- this.login.loading = false
- this.$store.commit('setUsername', res.data.username)
- this.closeAccountModal()
- }).catch(e => {
- this.login.loading = false
- this.ajaxErrorHandler(e, (error) => {
- let param = error.parameter
- if(this.login.errors[param] !== undefined) {
- this.login.errors[param] = error.message
- }
- })
- })
- }
- },
- created () {
- this.axios.get('/api/v1/settings')
- .then(res => {
- this.$store.commit('setForumName', res.data.forumName)
- }).catch(err => {
- if(err.response.data.errors[0].name === 'noSettings') {
- this.$router.push('/start')
- } else {
- this.ajaxErrorHandler(err)
- }
- })
- this.axios.get('/api/v1/category')
- .then(res => {
- this.$store.commit('addCategories', res.data)
- }).catch(this.ajaxErrorHandler)
- }
- }
- </script>
- <style lang='scss'>
- @import url('https://fonts.googleapis.com/css?family=Lato:300,300i,400|Montserrat');
- @import './assets/scss/variables.scss';
- html, body {
- width: 100%;
- height: 100%;
- margin: 0;
- padding: 0;
- color: $color__text--primary;
- @include text;
- }
- * {
- box-sizing: border-box;
- }
- .route_container {
- width: 80%;
- margin: 0 auto;
- margin-top: 2rem;
- padding-bottom: 2rem;
- }
- #app {
- padding-top: 4.5rem;
- height: 100%;
- }
- .header {
- width: 100%;
- padding: 1rem 2rem;
- position: fixed;
- top: 0;
- z-index: 2;
- background-color: #fff;
- display: flex;
- align-items: center;
- justify-content: space-between;
- border-bottom: 0.125rem solid $color__gray--primary;
- @at-root #{&}__group {
- display: flex;
- > * { margin: 0 0.5rem; }
- > *:first-child { margin-left: 0; }
- > *:last-child { margin-right: 0; }
- }
- }
- .logo {
- @include text($font--role-emphasis, 2rem, normal);
- @include user-select(none);
- cursor: pointer;
- }
- .button {
- border: 0.125rem solid $color__gray--primary;
- display: inline-block;
- text-align: center;
- @include text($font--role-default, 1rem, 400);
- padding: 0.5rem;
- cursor: pointer;
- background-color: #fff;
- transition: background-color 0.2s, border-color 0.2s;
- outline: none;
- &:hover {
- background-color: $color__lightgray--primary;
- border-color: $color__gray--darker;
- }
- &:active {
- background-color: $color__lightgray--darker;
- border-color: $color__gray--darkest;
- }
- @at-root #{&}__icon {
- }
- @at-root #{&}--borderless {
- border: 0;
- }
- @at-root #{&}--orange {
- border-color: $color__orange--primary;
- &:hover { border-color: $color__orange--darker; }
- &:active { border-color: $color__orange--darkest; }
- }
- @at-root #{&}--green {
- background-color: $color__green--primary;
- color: #fff;
- border-color: $color__green--darker;
- &:hover {
- border-color: $color__green--darker;
- background-color: rgba(75, 171, 79, 0.86);
- }
- &:active {
- border-color: $color__green--darker;
- background-color: $color__green--darkester;
- }
- }
- }
- .input {
- border: 0.125rem solid $color__gray--primary;
- @include text;
- padding: 0.25rem;
- outline: none;
- &:hover {
- border-color: $color__gray--darker;
- }
- &:focus {
- border-color: $color__gray--darkest;
- }
- }
- .search {
- border: 0.125rem solid $color__gray--primary;
- &:hover {
- border-color: $color__gray--darker;
- }
- &:focus {
- border-color: $color__gray--darkest;
- }
- @at-root #{&}__field {
- outline: none;
- height: 100%;
- padding: 0 0.5rem;
- border: 0;
- @include text;
- @include placeholder {
- @include text;
- }
- }
- }
- </style>
|