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>
</h1>
<h2 class="subtitle">
Lorem ipsum dolor sit amet, consectetur?
Do you want to authorize your contribution #{{ contributionIndex }}? Please sign in.
</h2>
<fieldset class="authorize">
<Form />
@ -25,6 +25,11 @@ export default {
components: {
Form
},
data() {
return {
contributionIndex: 1
}
},
computed: {
...mapGetters('user', ['isLoggedIn', 'hasErrorName']),
userHandle: {
@ -35,6 +40,8 @@ export default {
},
async mounted() {
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: {
...mapActions('user', ['getUserData'])

View File

@ -131,7 +131,11 @@ export default {
}
},
async mounted() {
this.loading = true
this.status.msg = 'Loading...'
this.status.type = ''
await this.getUserData()
this.loading = false
},
methods: {
...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_SECRET,
'1.0A',
process.env.TWITTER_CALLBACK_URL,
process.env.TWITTER_CALLBACK_URL || 'http://localhost:3000/api/twitter_callback',
'HMAC-SHA1'
)

View File

@ -2,6 +2,7 @@ const fs = require('fs').promises
const path = require('path')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const crypto = require('crypto')
const aws = require('aws-sdk')
const express = require('express')
const { Mutex } = require('async-mutex')
@ -72,13 +73,16 @@ router.post('/response', upload.single('response'), async (req, res) => {
let name = null
let company = null
let handle = null
let token = null
if (socialType !== 'anonymous' && req.body) {
name = req.body.name || null
company = req.body.company || 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')
if (process.env.DISABLE_S3 !== 'true') {

View File

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

View File

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