aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/login_form/login_form.js34
-rw-r--r--src/components/login_form/login_form.vue15
-rw-r--r--src/components/oauth_callback/oauth_callback.js20
-rw-r--r--src/components/oauth_callback/oauth_callback.vue5
-rw-r--r--src/components/registration/registration.js22
5 files changed, 82 insertions, 14 deletions
diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js
index 4405fb92..49868aed 100644
--- a/src/components/login_form/login_form.js
+++ b/src/components/login_form/login_form.js
@@ -1,22 +1,40 @@
+import oauthApi from '../../services/new_api/oauth.js'
const LoginForm = {
data: () => ({
user: {},
authError: false
}),
computed: {
+ loginMethod () { return this.$store.state.instance.loginMethod },
loggingIn () { return this.$store.state.users.loggingIn },
registrationOpen () { return this.$store.state.instance.registrationOpen }
},
methods: {
+ oAuthLogin () {
+ oauthApi.login({
+ oauth: this.$store.state.oauth,
+ instance: this.$store.state.instance.server,
+ commit: this.$store.commit
+ })
+ },
submit () {
- this.$store.dispatch('loginUser', this.user).then(
- () => {},
- (error) => {
- this.authError = error
- this.user.username = ''
- this.user.password = ''
- }
- )
+ const data = {
+ oauth: this.$store.state.oauth,
+ instance: this.$store.state.instance.server
+ }
+ oauthApi.getOrCreateApp(data).then((app) => {
+ oauthApi.getTokenWithCredentials(
+ {
+ app,
+ instance: data.instance,
+ username: this.user.username,
+ password: this.user.password})
+ .then((result) => {
+ this.$store.commit('setToken', result.access_token)
+ this.$store.dispatch('loginUser', result.access_token)
+ this.$router.push('/main/friends')
+ })
+ })
}
}
}
diff --git a/src/components/login_form/login_form.vue b/src/components/login_form/login_form.vue
index b7fed48a..12971882 100644
--- a/src/components/login_form/login_form.vue
+++ b/src/components/login_form/login_form.vue
@@ -5,7 +5,7 @@
{{$t('login.login')}}
</div>
<div class="panel-body">
- <form v-on:submit.prevent='submit(user)' class='login-form'>
+ <form v-if="loginMethod == 'password'" v-on:submit.prevent='submit(user)' class='login-form'>
<div class='form-group'>
<label for='username'>{{$t('login.username')}}</label>
<input :disabled="loggingIn" v-model='user.username' class='form-control' id='username' v-bind:placeholder="$t('login.placeholder')">
@@ -20,8 +20,17 @@
<button :disabled="loggingIn" type='submit' class='btn btn-default'>{{$t('login.login')}}</button>
</div>
</div>
- <div v-if="authError" class='form-group'>
- <div class='alert error'>{{authError}}</div>
+ </form>
+
+ <form v-if="loginMethod == 'token'" v-on:submit.prevent='oAuthLogin' class="login-form">
+ <div class="form-group">
+ <p>{{$t('login.description')}}</p>
+ </div>
+ <div class='form-group'>
+ <div class='login-bottom'>
+ <div><router-link :to="{name: 'registration'}" v-if='registrationOpen' class='register'>{{$t('login.register')}}</router-link></div>
+ <button :disabled="loggingIn" type='submit' class='btn btn-default'>{{$t('login.login')}}</button>
+ </div>
</div>
</form>
</div>
diff --git a/src/components/oauth_callback/oauth_callback.js b/src/components/oauth_callback/oauth_callback.js
new file mode 100644
index 00000000..7a5132ad
--- /dev/null
+++ b/src/components/oauth_callback/oauth_callback.js
@@ -0,0 +1,20 @@
+import oauth from '../../services/new_api/oauth.js'
+
+const oac = {
+ props: ['code'],
+ mounted () {
+ if (this.code) {
+ oauth.getToken({
+ app: this.$store.state.oauth,
+ instance: this.$store.state.instance.server,
+ code: this.code
+ }).then((result) => {
+ this.$store.commit('setToken', result.access_token)
+ this.$store.dispatch('loginUser', result.access_token)
+ this.$router.push('/main/friends')
+ })
+ }
+ }
+}
+
+export default oac
diff --git a/src/components/oauth_callback/oauth_callback.vue b/src/components/oauth_callback/oauth_callback.vue
new file mode 100644
index 00000000..9c806916
--- /dev/null
+++ b/src/components/oauth_callback/oauth_callback.vue
@@ -0,0 +1,5 @@
+<template>
+ <h1>...</h1>
+</template>
+
+<script src="./oauth_callback.js"></script>
diff --git a/src/components/registration/registration.js b/src/components/registration/registration.js
index 8f59878d..f7f8a720 100644
--- a/src/components/registration/registration.js
+++ b/src/components/registration/registration.js
@@ -1,3 +1,5 @@
+import oauthApi from '../../services/new_api/oauth.js'
+
const registration = {
data: () => ({
user: {},
@@ -25,9 +27,23 @@ const registration = {
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
+ const data = {
+ oauth: this.$store.state.oauth,
+ instance: this.$store.state.instance.server
+ }
+ oauthApi.getOrCreateApp(data).then((app) => {
+ oauthApi.getTokenWithCredentials(
+ {
+ app,
+ instance: data.instance,
+ username: this.user.username,
+ password: this.user.password})
+ .then((result) => {
+ this.$store.commit('setToken', result.access_token)
+ this.$store.dispatch('loginUser', result.access_token)
+ this.$router.push('/main/friends')
+ })
+ })
} else {
this.registering = false
response.json().then((data) => {