diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js index 1a6f6015..a117b76f 100644 --- a/src/components/login_form/login_form.js +++ b/src/components/login_form/login_form.js @@ -4,7 +4,8 @@ const LoginForm = { authError: false }), computed: { - loggingIn () { return this.$store.state.users.loggingIn } + loggingIn () { return this.$store.state.users.loggingIn }, + registrationOpen () { return this.$store.state.config.registrationOpen } }, methods: { submit () { diff --git a/src/components/login_form/login_form.vue b/src/components/login_form/login_form.vue index b2fa5341..d6291148 100644 --- a/src/components/login_form/login_form.vue +++ b/src/components/login_form/login_form.vue @@ -15,7 +15,10 @@
- +
+
Register
+ +
{{authError}}
@@ -39,8 +42,8 @@ } .btn { - margin-top: 1.0em; min-height: 28px; + width: 10em; } .error { @@ -50,6 +53,18 @@ min-height: 28px; line-height: 28px; } + + .register { + flex: 1 1; + } + + .login-bottom { + margin-top: 1.0em; + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + } } diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index a95f92ab..a17d6479 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -80,6 +80,18 @@ } } + + .btn { + cursor: pointer; + } + + .btn[disabled] { + cursor: not-allowed; + } + + .icon-cancel { + cursor: pointer; + } form { display: flex; flex-direction: column; diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js new file mode 100644 index 00000000..771b3b27 --- /dev/null +++ b/src/components/registration/registration.js @@ -0,0 +1,37 @@ +const registration = { + data: () => ({ + user: {}, + error: false, + registering: false + }), + created () { + if (!this.$store.state.config.registrationOpen || !!this.$store.state.users.currentUser) { + this.$router.push('/main/all') + } + }, + computed: { + termsofservice () { return this.$store.state.config.tos } + }, + methods: { + submit () { + this.registering = true + this.user.nickname = this.user.username + this.$store.state.api.backendInteractor.register(this.user).then( + (response) => { + if (response.ok) { + this.$store.dispatch('loginUser', this.user) + this.$router.push('/main/all') + this.registering = false + } else { + this.registering = false + response.json().then((data) => { + this.error = data.error + }) + } + } + ) + } + } +} + +export default registration diff --git a/src/components/registration/registration.vue b/src/components/registration/registration.vue new file mode 100644 index 00000000..bb3e5e04 --- /dev/null +++ b/src/components/registration/registration.vue @@ -0,0 +1,134 @@ + + + + diff --git a/src/components/settings/settings.js b/src/components/settings/settings.js index 998aa354..8d6a6713 100644 --- a/src/components/settings/settings.js +++ b/src/components/settings/settings.js @@ -7,14 +7,58 @@ const settings = { hideAttachmentsLocal: this.$store.state.config.hideAttachments, hideAttachmentsInConvLocal: this.$store.state.config.hideAttachmentsInConv, hideNsfwLocal: this.$store.state.config.hideNsfw, + muteWordsString: this.$store.state.config.muteWords.join('\n'), autoLoadLocal: this.$store.state.config.autoLoad, hoverPreviewLocal: this.$store.state.config.hoverPreview, - muteWordsString: this.$store.state.config.muteWords.join('\n') + previewfile: null } }, components: { StyleSwitcher }, + computed: { + user () { + return this.$store.state.users.currentUser + } + }, + methods: { + uploadAvatar ({target}) { + const file = target.files[0] + // eslint-disable-next-line no-undef + const reader = new FileReader() + reader.onload = ({target}) => { + const img = target.result + this.previewfile = img + } + reader.readAsDataURL(file) + }, + submitAvatar () { + if (!this.previewfile) { return } + + const img = this.previewfile + // eslint-disable-next-line no-undef + let imginfo = new Image() + let cropX, cropY, cropW, cropH + imginfo.src = this.previewfile + if (imginfo.height > imginfo.width) { + cropX = 0 + cropW = imginfo.width + cropY = Math.floor((imginfo.height - imginfo.width) / 2) + cropH = imginfo.width + } else { + cropY = 0 + cropH = imginfo.height + cropX = Math.floor((imginfo.width - imginfo.height) / 2) + cropW = imginfo.height + } + this.$store.state.api.backendInteractor.updateAvatar({params: {img, cropX, cropY, cropW, cropH}}).then((user) => { + if (!user.error) { + this.$store.commit('addNewUsers', [user]) + this.$store.commit('setCurrentUser', user) + } + }) + } + }, watch: { hideAttachmentsLocal (value) { this.$store.dispatch('setOption', { name: 'hideAttachments', value }) diff --git a/src/components/settings/settings.vue b/src/components/settings/settings.vue index af0242c4..1abb1789 100644 --- a/src/components/settings/settings.vue +++ b/src/components/settings/settings.vue @@ -8,6 +8,18 @@

Theme

+
+

Avatar

+

Your current avatar:

+ +

Set new avatar:

+ + +
+ +
+ +

Filtering

All notices containing these words will be muted, one per line

@@ -52,6 +64,24 @@ width: 100%; height: 100px; } + + .old-avatar { + width: 128px; + border-radius: 5px; + } + + .new-avatar { + object-fit: cover; + width: 128px; + height: 128px; + border-radius: 5px; + } + + .btn { + margin-top: 1em; + min-height: 28px; + width: 10em; + } } .setting-list { list-style-type: none; diff --git a/src/main.js b/src/main.js index e5ecf228..4b7891ed 100644 --- a/src/main.js +++ b/src/main.js @@ -9,6 +9,7 @@ import ConversationPage from './components/conversation-page/conversation-page.v import Mentions from './components/mentions/mentions.vue' import UserProfile from './components/user_profile/user_profile.vue' import Settings from './components/settings/settings.vue' +import Registration from './components/registration/registration.vue' import statusesModule from './modules/statuses.js' import usersModule from './modules/users.js' @@ -60,7 +61,8 @@ const routes = [ { name: 'conversation', path: '/notice/:id', component: ConversationPage, meta: { dontScroll: true } }, { name: 'user-profile', path: '/users/:id', component: UserProfile }, { name: 'mentions', path: '/:username/mentions', component: Mentions }, - { name: 'settings', path: '/settings', component: Settings } + { name: 'settings', path: '/settings', component: Settings }, + { name: 'registration', path: '/registration', component: Registration } ] const router = new VueRouter({ @@ -84,9 +86,16 @@ new Vue({ window.fetch('/static/config.json') .then((res) => res.json()) - .then(({name, theme, background, logo}) => { + .then(({name, theme, background, logo, registrationOpen}) => { store.dispatch('setOption', { name: 'name', value: name }) store.dispatch('setOption', { name: 'theme', value: theme }) store.dispatch('setOption', { name: 'background', value: background }) store.dispatch('setOption', { name: 'logo', value: logo }) + store.dispatch('setOption', { name: 'registrationOpen', value: registrationOpen }) + }) + +window.fetch('/static/terms-of-service.html') + .then((res) => res.text()) + .then((html) => { + store.dispatch('setOption', { name: 'tos', value: html }) }) diff --git a/src/modules/users.js b/src/modules/users.js index 22e0133c..b68f67e6 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -24,7 +24,7 @@ export const mutations = { set(user, 'muted', muted) }, setCurrentUser (state, user) { - state.currentUser = user + state.currentUser = merge(state.currentUser || {}, user) }, beginLogin (state) { state.loggingIn = true diff --git a/src/services/api/api.service.js b/src/services/api/api.service.js index 59e3a1c3..e848d076 100644 --- a/src/services/api/api.service.js +++ b/src/services/api/api.service.js @@ -17,13 +17,15 @@ const FRIENDS_URL = '/api/statuses/friends.json' const FOLLOWING_URL = '/api/friendships/create.json' const UNFOLLOWING_URL = '/api/friendships/destroy.json' const QVITTER_USER_PREF_URL = '/api/qvitter/set_profile_pref.json' +const REGISTRATION_URL = '/api/account/register.json' +const AVATAR_UPDATE_URL = '/api/qvitter/update_avatar.json' const EXTERNAL_PROFILE_URL = '/api/externalprofile/show.json' const QVITTER_USER_TIMELINE_URL = '/api/qvitter/statuses/user_timeline.json' // const USER_URL = '/api/users/show.json' -const oldfetch = window.fetch +import { each, map } from 'lodash' -import { map } from 'lodash' +const oldfetch = window.fetch let fetch = (url, options) => { const baseUrl = '' @@ -31,6 +33,55 @@ let fetch = (url, options) => { return oldfetch(fullUrl, options) } +// Params +// cropH +// cropW +// cropX +// cropY +// img (base 64 encodend data url) +const updateAvatar = ({credentials, params}) => { + let url = AVATAR_UPDATE_URL + + const form = new FormData() + + each(params, (value, key) => { + if (value) { + form.append(key, value) + } + }) + return fetch(url, { + headers: authHeaders(credentials), + method: 'POST', + body: form + }).then((data) => data.json()) +} + +// Params needed: +// nickname +// email +// fullname +// password +// password_confirm +// +// Optional +// bio +// homepage +// location +const register = (params) => { + const form = new FormData() + + each(params, (value, key) => { + if (value) { + form.append(key, value) + } + }) + + return fetch(REGISTRATION_URL, { + method: 'POST', + body: form + }) +} + const authHeaders = (user) => { if (user && user.username && user.password) { return { 'Authorization': `Basic ${btoa(`${user.username}:${user.password}`)}` } @@ -220,6 +271,8 @@ const apiService = { fetchAllFollowing, setUserMute, fetchMutes, + register, + updateAvatar, externalProfile } diff --git a/src/services/backend_interactor_service/backend_interactor_service.js b/src/services/backend_interactor_service/backend_interactor_service.js index f2d01c70..5dbbf4b3 100644 --- a/src/services/backend_interactor_service/backend_interactor_service.js +++ b/src/services/backend_interactor_service/backend_interactor_service.js @@ -36,6 +36,8 @@ const backendInteractorService = (credentials) => { const fetchMutes = () => apiService.fetchMutes({credentials}) + const register = (params) => apiService.register(params) + const updateAvatar = ({params}) => apiService.updateAvatar({credentials, params}) const externalProfile = (profileUrl) => apiService.externalProfile(profileUrl) const backendInteractorServiceInstance = { @@ -49,6 +51,8 @@ const backendInteractorService = (credentials) => { startFetching, setUserMute, fetchMutes, + register, + updateAvatar, externalProfile } diff --git a/static/config.json b/static/config.json index 3b6d56c4..195ee046 100644 --- a/static/config.json +++ b/static/config.json @@ -2,5 +2,6 @@ "name": "Pleroma FE", "theme": "base16-pleroma-dark.css", "background": "/static/bg.jpg", - "logo": "/static/logo.png" + "logo": "/static/logo.png", + "registrationOpen": false } diff --git a/static/terms-of-service.html b/static/terms-of-service.html new file mode 100644 index 00000000..c02cb719 --- /dev/null +++ b/static/terms-of-service.html @@ -0,0 +1,7 @@ +

Terms of Service

+ +

This is a placeholder ToS.

+ +

Edit "/static/terms-of-service.html" to make it fit the needs of your instance.

+
+