This commit is contained in:
Alexey 2020-02-07 12:21:53 +03:00
parent d03f81f81f
commit 640443dc2d
6 changed files with 20 additions and 6 deletions

View File

@ -4,7 +4,7 @@
Hello, <span>@{{ userHandle }}</span> Hello, <span>@{{ userHandle }}</span>
</h1> </h1>
<h2 class="subtitle"> <h2 class="subtitle">
Lorem ipsum dolor sit amet, consectetur? Do you want to authorize your contribution #{{ contributionIndex }}? Please sign in.
</h2> </h2>
<fieldset class="authorize"> <fieldset class="authorize">
<Form /> <Form />
@ -25,6 +25,11 @@ export default {
components: { components: {
Form Form
}, },
data() {
return {
contributionIndex: 1
}
},
computed: { computed: {
...mapGetters('user', ['isLoggedIn', 'hasErrorName']), ...mapGetters('user', ['isLoggedIn', 'hasErrorName']),
userHandle: { userHandle: {
@ -35,6 +40,8 @@ export default {
}, },
async mounted() { async mounted() {
await this.getUserData() await this.getUserData()
// TODO. parse href to take token (it's supposed to be after #)
// then you need to store it in localstorage OR pass to server (to `/connect`) so after the authorization redirect server can put it in url
}, },
methods: { methods: {
...mapActions('user', ['getUserData']) ...mapActions('user', ['getUserData'])

View File

@ -131,7 +131,11 @@ export default {
} }
}, },
async mounted() { async mounted() {
this.loading = true
this.status.msg = 'Loading...'
this.status.type = ''
await this.getUserData() await this.getUserData()
this.loading = false
}, },
methods: { methods: {
...mapActions('user', ['makeTweet', 'logOut', 'getUserData']), ...mapActions('user', ['makeTweet', 'logOut', 'getUserData']),

View File

@ -9,7 +9,7 @@ const consumer = new oauth.OAuth(
process.env.TWITTER_CONSUMER_KEY, process.env.TWITTER_CONSUMER_KEY,
process.env.TWITTER_CONSUMER_SECRET, process.env.TWITTER_CONSUMER_SECRET,
'1.0A', '1.0A',
process.env.TWITTER_CALLBACK_URL, process.env.TWITTER_CALLBACK_URL || 'http://localhost:3000/api/twitter_callback',
'HMAC-SHA1' 'HMAC-SHA1'
) )

View File

@ -2,6 +2,7 @@ const fs = require('fs').promises
const path = require('path') const path = require('path')
const util = require('util') const util = require('util')
const exec = util.promisify(require('child_process').exec) const exec = util.promisify(require('child_process').exec)
const crypto = require('crypto')
const aws = require('aws-sdk') const aws = require('aws-sdk')
const express = require('express') const express = require('express')
const { Mutex } = require('async-mutex') const { Mutex } = require('async-mutex')
@ -72,13 +73,16 @@ router.post('/response', upload.single('response'), async (req, res) => {
let name = null let name = null
let company = null let company = null
let handle = null let handle = null
let token = null
if (socialType !== 'anonymous' && req.body) { if (socialType !== 'anonymous' && req.body) {
name = req.body.name || null name = req.body.name || null
company = req.body.company || null company = req.body.company || null
handle = req.session.handle || null handle = req.session.handle || null
} else {
token = crypto.randomBytes(32).toString('hex')
} }
await Contribution.create({ name, company, handle, socialType }) await Contribution.create({ name, company, handle, socialType, token })
console.log('Contribution is correct, uploading to storage') console.log('Contribution is correct, uploading to storage')
if (process.env.DISABLE_S3 !== 'true') { if (process.env.DISABLE_S3 !== 'true') {

View File

@ -7,8 +7,8 @@ const morgan = require('morgan')
const session = require('express-session') const session = require('express-session')
const { Nuxt, Builder } = require('nuxt') const { Nuxt, Builder } = require('nuxt')
const config = require('../nuxt.config.js') const config = require('../nuxt.config.js')
const sessionsController = require('./controllers/sessions') const sessionsController = require('./controllers/authorize')
const contributionController = require('./controllers/contributions') const contributionController = require('./controllers/contribute')
const models = require('./models') const models = require('./models')
const app = express() const app = express()

View File

@ -13,7 +13,6 @@ module.exports = (sequelize, DataTypes) => {
{ {
hooks: { hooks: {
beforeCreate: (contribution, options) => { beforeCreate: (contribution, options) => {
console.log('contribution', contribution.dataValues)
const { name, company, socialType } = contribution.dataValues const { name, company, socialType } = contribution.dataValues
if (socialType !== 'anonymous' && (name.length < 4 || name.length > 35)) { if (socialType !== 'anonymous' && (name.length < 4 || name.length > 35)) {
throw new Error('Wrong name') throw new Error('Wrong name')