merge #1588 and resolve conflicts

This commit is contained in:
ogerly 2022-03-21 14:57:43 +01:00
commit 2ea7cf6705
26 changed files with 101 additions and 104 deletions

View File

@ -1,7 +1,7 @@
import gql from 'graphql-tag'
export const confirmPendingCreation = gql`
mutation ($id: Float!) {
mutation ($id: Int!) {
confirmPendingCreation(id: $id)
}
`

View File

@ -1,7 +1,7 @@
import gql from 'graphql-tag'
export const deletePendingCreation = gql`
mutation ($id: Float!) {
mutation ($id: Int!) {
deletePendingCreation(id: $id)
}
`

View File

@ -1,7 +1,7 @@
import gql from 'graphql-tag'
export const deleteUser = gql`
mutation ($userId: Float!) {
mutation ($userId: Int!) {
deleteUser(userId: $userId)
}
`

View File

@ -1,7 +1,7 @@
import gql from 'graphql-tag'
export const unDeleteUser = gql`
mutation ($userId: Float!) {
mutation ($userId: Int!) {
unDeleteUser(userId: $userId)
}
`

View File

@ -99,7 +99,7 @@ export default {
},
updateDeletedAt(userId, deletedAt) {
this.searchResult.find((obj) => obj.userId === userId).deletedAt = deletedAt
this.toastSuccess(this.$t('user_deleted'))
this.toastSuccess(deletedAt ? this.$t('user_deleted') : this.$t('user_recovered'))
},
},
watch: {

View File

@ -40,7 +40,7 @@ EMAIL_SMTP_URL=gmail.com
EMAIL_SMTP_PORT=587
EMAIL_LINK_VERIFICATION=http://localhost/checkEmail/{code}
EMAIL_LINK_SETPASSWORD=http://localhost/reset/{code}
RESEND_TIME=10
EMAIL_CODE_VALID_TIME=10
# Webhook
WEBHOOK_ELOPAGE_SECRET=secret

View File

@ -8,4 +8,5 @@ export const INALIENABLE_RIGHTS = [
RIGHTS.SEND_RESET_PASSWORD_EMAIL,
RIGHTS.SET_PASSWORD,
RIGHTS.QUERY_TRANSACTION_LINK,
RIGHTS.QUERY_OPT_IN,
]

View File

@ -16,6 +16,7 @@ export enum RIGHTS {
CREATE_USER = 'CREATE_USER',
SEND_RESET_PASSWORD_EMAIL = 'SEND_RESET_PASSWORD_EMAIL',
SET_PASSWORD = 'SET_PASSWORD',
QUERY_OPT_IN = 'QUERY_OPT_IN',
UPDATE_USER_INFOS = 'UPDATE_USER_INFOS',
HAS_ELOPAGE = 'HAS_ELOPAGE',
CREATE_TRANSACTION_LINK = 'CREATE_TRANSACTION_LINK',

View File

@ -54,8 +54,6 @@ const loginServer = {
LOGIN_SERVER_KEY: process.env.LOGIN_SERVER_KEY || 'a51ef8ac7ef1abf162fb7a65261acd7a',
}
// TODO: Hannes if I find you... this looks like blasphemy
const resendTime = parseInt(process.env.RESEND_TIME ? process.env.RESEND_TIME : 'null')
const email = {
EMAIL: process.env.EMAIL === 'true' || false,
EMAIL_USERNAME: process.env.EMAIL_USERNAME || 'gradido_email',
@ -67,7 +65,9 @@ const email = {
process.env.EMAIL_LINK_VERIFICATION || 'http://localhost/checkEmail/{code}',
EMAIL_LINK_SETPASSWORD:
process.env.EMAIL_LINK_SETPASSWORD || 'http://localhost/reset-password/{code}',
RESEND_TIME: isNaN(resendTime) ? 10 : resendTime,
EMAIL_CODE_VALID_TIME: process.env.EMAIL_CODE_VALID_TIME
? parseInt(process.env.EMAIL_CODE_VALID_TIME) || 10
: 10,
}
const webhook = {

View File

@ -127,7 +127,10 @@ export class AdminResolver {
@Authorized([RIGHTS.DELETE_USER])
@Mutation(() => Date, { nullable: true })
async deleteUser(@Arg('userId') userId: number, @Ctx() context: any): Promise<Date | null> {
async deleteUser(
@Arg('userId', () => Int) userId: number,
@Ctx() context: any,
): Promise<Date | null> {
const user = await dbUser.findOne({ id: userId })
// user exists ?
if (!user) {
@ -146,7 +149,7 @@ export class AdminResolver {
@Authorized([RIGHTS.UNDELETE_USER])
@Mutation(() => Date, { nullable: true })
async unDeleteUser(@Arg('userId') userId: number): Promise<Date | null> {
async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise<Date | null> {
const user = await dbUser.findOne({ id: userId }, { withDeleted: true })
// user exists ?
if (!user) {
@ -288,7 +291,7 @@ export class AdminResolver {
@Authorized([RIGHTS.DELETE_PENDING_CREATION])
@Mutation(() => Boolean)
async deletePendingCreation(@Arg('id') id: number): Promise<boolean> {
async deletePendingCreation(@Arg('id', () => Int) id: number): Promise<boolean> {
const entity = await AdminPendingCreation.findOneOrFail(id)
const res = await AdminPendingCreation.delete(entity)
return !!res
@ -296,7 +299,10 @@ export class AdminResolver {
@Authorized([RIGHTS.CONFIRM_PENDING_CREATION])
@Mutation(() => Boolean)
async confirmPendingCreation(@Arg('id') id: number, @Ctx() context: any): Promise<boolean> {
async confirmPendingCreation(
@Arg('id', () => Int) id: number,
@Ctx() context: any,
): Promise<boolean> {
const pendingCreation = await AdminPendingCreation.findOneOrFail(id)
const moderatorUser = context.user
if (moderatorUser.id === pendingCreation.userId)

View File

@ -156,15 +156,11 @@ const createEmailOptIn = async (
emailOptInTypeId: EMAIL_OPT_IN_REGISTER,
})
if (emailOptIn) {
const timeElapsed = Date.now() - new Date(emailOptIn.updatedAt).getTime()
if (timeElapsed <= parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) {
throw new Error(
'email already sent less than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes ago',
)
} else {
emailOptIn.updatedAt = new Date()
emailOptIn.resendCount++
if (isOptInCodeValid(emailOptIn)) {
throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
}
emailOptIn.updatedAt = new Date()
emailOptIn.resendCount++
} else {
emailOptIn = new LoginEmailOptIn()
emailOptIn.verificationCode = random(64)
@ -185,17 +181,13 @@ const getOptInCode = async (loginUserId: number): Promise<LoginEmailOptIn> => {
emailOptInTypeId: EMAIL_OPT_IN_RESET_PASSWORD,
})
// Check for 10 minute delay
// Check for `CONFIG.EMAIL_CODE_VALID_TIME` minute delay
if (optInCode) {
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
if (timeElapsed <= parseInt(CONFIG.RESEND_TIME.toString()) * 60 * 1000) {
throw new Error(
'email already sent less than ' + parseInt(CONFIG.RESEND_TIME.toString()) + ' minutes ago',
)
} else {
optInCode.updatedAt = new Date()
optInCode.resendCount++
if (isOptInCodeValid(optInCode)) {
throw new Error(`email already sent less than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
}
optInCode.updatedAt = new Date()
optInCode.resendCount++
} else {
optInCode = new LoginEmailOptIn()
optInCode.verificationCode = random(64)
@ -497,10 +489,9 @@ export class UserResolver {
throw new Error('Could not login with emailVerificationCode')
})
// Code is only valid for 10minutes
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
if (timeElapsed > 10 * 60 * 1000) {
throw new Error('Code is older than 10 minutes')
// Code is only valid for `CONFIG.EMAIL_CODE_VALID_TIME` minutes
if (!isOptInCodeValid(optInCode)) {
throw new Error(`email already more than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
}
// load user
@ -573,6 +564,17 @@ export class UserResolver {
return true
}
@Authorized([RIGHTS.QUERY_OPT_IN])
@Query(() => Boolean)
async queryOptIn(@Arg('optIn') optIn: string): Promise<boolean> {
const optInCode = await LoginEmailOptIn.findOneOrFail({ verificationCode: optIn })
// Code is only valid for `CONFIG.EMAIL_CODE_VALID_TIME` minutes
if (!isOptInCodeValid(optInCode)) {
throw new Error(`email was sent more than $(CONFIG.EMAIL_CODE_VALID_TIME} minutes ago`)
}
return true
}
@Authorized([RIGHTS.UPDATE_USER_INFOS])
@Mutation(() => Boolean)
async updateUserInfos(
@ -674,3 +676,7 @@ export class UserResolver {
return hasElopageBuys(userEntity.email)
}
}
function isOptInCodeValid(optInCode: LoginEmailOptIn) {
const timeElapsed = Date.now() - new Date(optInCode.updatedAt).getTime()
return timeElapsed <= CONFIG.EMAIL_CODE_VALID_TIME * 60 * 1000
}

View File

@ -96,7 +96,7 @@ export const createPendingCreation = gql`
`
export const confirmPendingCreation = gql`
mutation ($id: Float!) {
mutation ($id: Int!) {
confirmPendingCreation(id: $id)
}
`

View File

@ -19,7 +19,7 @@
<div class="mt-4" v-show="selected === sendTypes.link">
<h2 class="alert-heading">{{ $t('gdd_per_link.header') }}</h2>
<div>
{{ $t('gdd_per_link.sentence_1') }}
{{ $t('gdd_per_link.choose-amount') }}
</div>
</div>

View File

@ -2,7 +2,7 @@
<div class="redeem-information">
<b-jumbotron bg-variant="muted" text-variant="dark" border-variant="info">
<h1>
{{ user.firstName }}
{{ firstName }}
{{ $t('transaction-link.send_you') }} {{ amount | GDD }}
</h1>
<b>{{ memo }}</b>
@ -13,7 +13,7 @@
export default {
name: 'RedeemInformation',
props: {
user: { type: Object, required: true },
firstName: { type: String, required: true },
amount: { type: String, required: true },
memo: { type: String, required: true, default: '' },
},

View File

@ -1,6 +1,6 @@
<template>
<div class="redeem-logged-out">
<redeem-information :user="user" :amount="amount" :memo="memo" />
<redeem-information :firstName="user.firstName" :amount="amount" :memo="memo" />
<b-jumbotron>
<div class="mb-6">

View File

@ -1,6 +1,6 @@
<template>
<div class="redeem-self-creator">
<redeem-information :user="user" :amount="amount" :memo="memo" />
<redeem-information :firstName="user.firstName" :amount="amount" :memo="memo" />
<b-jumbotron>
<div class="mb-3 text-center">

View File

@ -1,6 +1,6 @@
<template>
<div class="redeem-valid">
<redeem-information :user="user" :amount="amount" :memo="memo" />
<redeem-information :firstName="user.firstName" :amount="amount" :memo="memo" />
<b-jumbotron>
<div class="mb-3 text-center">
<b-button variant="primary" @click="$emit('redeem-link', amount)" size="lg">

View File

@ -119,6 +119,12 @@ export const communities = gql`
}
`
export const queryOptIn = gql`
query($optIn: String!) {
queryOptIn(optIn: $optIn)
}
`
export const queryTransactionLink = gql`
query($code: String!) {
queryTransactionLink(code: $code) {

View File

@ -94,13 +94,14 @@
},
"GDD": "GDD",
"gdd_per_link": {
"choose-amount": "Wähle einen Betrag aus, welchen du per Link versenden möchtest. Du kannst auch noch eine Nachricht eintragen. Beim Klick „jetzt generieren“ wird ein Link erstellt, den du versenden kannst.",
"copy": "kopieren",
"created": "Der Link wurde erstellt!",
"decay-14-day": "Vergänglichkeit für 14 Tage",
"delete-the-link": "Den Link löschen?",
"deleted": "Der Link wurde gelöscht!",
"expired": "Abgelaufen",
"has-account": "Du hast ein Gradido Konto",
"has-account": "Du besitzt bereits ein Gradido Konto",
"header": "Gradidos versenden per Link",
"link-copied": "Link wurde in die Zwischenablage kopiert",
"link-deleted": "Der Link wurde am {date} gelöscht.",
@ -108,15 +109,13 @@
"link-overview": "Linkübersicht",
"links_count": "Aktive Links",
"links_sum": "Summe deiner versendeten Gradidos",
"no-account": "Du hast noch kein Gradido Konto",
"no-redeem": "Du kannst deinen eigenen Link nicht einlösen!",
"no-account": "Du besitzt noch kein Gradido Konto",
"no-redeem": "Du darfst deinen eigenen Link nicht einlösen!",
"not-copied": "Konnte den Link nicht kopieren: {err}",
"redeem": "Einlösen",
"redeem-text": "Willst du den Betrag jetzt einlösen?",
"redeemed": "Erfolgreich eingelöst! Deinem Konto wurden {n} GDD gutgeschrieben.",
"successfully-redeemed": "Erfolgreich eingelöst!",
"redeemed-at": "Der Link wurde bereits am {date} eingelöst.",
"sentence_1": "Wähle einen Betrag aus, welchen du per Link versenden möchtest. Du kannst auch noch eine Nachricht eintragen. Beim Klick „jetzt generieren“ wird ein Link erstellt, den du versenden kannst.",
"to-login": "Log dich ein",
"to-register": "Registriere ein neues Konto"
},
@ -220,13 +219,14 @@
"uppercase": "Großbuchstabe erforderlich."
},
"thx": {
"activateEmail": "Dein Konto wurde noch nicht aktiviert. Bitte überprüfe deine E-Mail und klicke den Aktivierungslink!",
"activateEmail": "Dein Konto wurde noch nicht aktiviert. Bitte überprüfe deine E-Mail und klicke den Aktivierungslink oder fordere einen neuen Aktivierungslink über die Password Reset Seite.",
"checkEmail": "Deine E-Mail wurde erfolgreich verifiziert. Du kannst dich jetzt anmelden.",
"email": "Wir haben dir eine E-Mail gesendet.",
"emailActivated": "Danke dass Du deine E-Mail bestätigt hast.",
"errorTitle": "Achtung!",
"register": "Du bist jetzt registriert, bitte überprüfe deine Emails und klicke auf den Aktivierungslink.",
"reset": "Dein Passwort wurde geändert.",
"resetPassword": "Den Code den Du genutzt hast ist zu alt bitte fordere ein neuen über die Passwort Reset Seite an.",
"title": "Danke!"
}
},

View File

@ -94,13 +94,14 @@
},
"GDD": "GDD",
"gdd_per_link": {
"choose-amount": "Select an amount that you would like to send via link. You can also enter a message. Click 'Generate now' to create a link that you can share.",
"copy": "copy",
"created": "Link was created!",
"decay-14-day": "Decay for 14 days",
"delete-the-link": "Delete the link?",
"deleted": "The link was deleted!",
"expired": "Expired",
"has-account": "You have a Gradido account",
"has-account": "You already have a Gradido account",
"header": "Send Gradidos via link",
"link-copied": "Link copied to clipboard",
"link-deleted": "The link was deleted on {date}.",
@ -109,14 +110,12 @@
"links_count": "Active links",
"links_sum": "Total of your sent Gradidos",
"no-account": "You don't have a Gradido account yet",
"no-redeem": "You can't redeem your own link!",
"no-redeem": "You not allowed to redeem your own link!",
"not-copied": "Could not copy link: {err}",
"redeem": "Redeem",
"redeem-text": "Do you want to redeem the amount now?",
"redeemed": "Successfully redeemed! Your account has been credited with {n} GDD.",
"redeemed-at": "The link was already redeemed on {date}.",
"successfully-redeemed": "Successfully redeemed!",
"sentence_1": "Select an amount that you would like to send via link. You can also enter a message. Click 'Generate now' to create a link that you can share.",
"to-login": "Log in",
"to-register": "Register a new account"
},
@ -220,13 +219,14 @@
"uppercase": "One uppercase letter required."
},
"thx": {
"activateEmail": "Your account has not been activated yet, please check your emails and click the activation link!",
"activateEmail": "Your account has not been activated yet, please check your emails and click the activation link or order a new activation link over the password reset page.",
"checkEmail": "Your email has been successfully verified. You can sign in now.",
"email": "We have sent you an email.",
"emailActivated": "Thank you your email has been activated.",
"errorTitle": "Attention!",
"register": "You are registered now, please check your emails and click the activation link.",
"reset": "Your password has been changed.",
"resetPassword": "The code you used was to old please order a new on over the password reset page.",
"title": "Thank you!"
}
},

View File

@ -42,10 +42,6 @@
</validation-observer>
</b-card-body>
</b-card>
<div v-if="$route.params.code" class="mt-2 mb-2">
{{ $t('gdd_per_link.redeem') + ':' }}
<b>{{ $route.params.code }}</b>
</div>
<b-row class="mt-3">
<b-col cols="6" class="text-center text-sm-left col-12 col-sm-6 pb-5">
<router-link to="/forgot-password" class="mt-3">
@ -68,7 +64,6 @@ import InputPassword from '@/components/Inputs/InputPassword'
import InputEmail from '@/components/Inputs/InputEmail'
import { login } from '@/graphql/queries'
import { getCommunityInfoMixin } from '@/mixins/getCommunityInfo'
import { redeemTransactionLink } from '@/graphql/mutations'
export default {
name: 'Login',
@ -101,16 +96,17 @@ export default {
},
fetchPolicy: 'network-only',
})
.then((result) => {
.then(async (result) => {
const {
data: { login },
} = result
this.$store.dispatch('login', login)
await loader.hide()
if (this.$route.params.code) {
this.redeemLink(this.$route.params.code)
this.$router.push(`/redeem/${this.$route.params.code}`)
} else {
this.$router.push('/overview')
}
this.$router.push('/overview')
loader.hide()
})
.catch((error) => {
this.toastError(this.$t('error.no-account'))
@ -122,21 +118,6 @@ export default {
loader.hide()
})
},
redeemLink(code) {
this.$apollo
.mutate({
mutation: redeemTransactionLink,
variables: {
code: code,
},
})
.then(() => {
this.toastSuccess(this.$t('gdd_per_link.successfully-redeemed'))
})
.catch((err) => {
this.toastError(err.message)
})
},
},
}
</script>

View File

@ -118,30 +118,8 @@
{{ messageError }}
</span>
</b-alert>
<b-row v-if="redeemCode">
<b-col>
<label>{{ $t('gdd_per_link.redeem') }}</label>
<div class="mt-2 mb-2">
<b-input-group class="shadow-sm p-2 bg-white rounded">
<b-input-group-prepend is-text>
<b-icon icon="link45deg"></b-icon>
</b-input-group-prepend>
<b-form-input
readonly
id="redeem-code"
type="text"
v-model="redeemCode"
></b-form-input>
</b-input-group>
</div>
</b-col>
</b-row>
<b-row
v-else
v-b-toggle:my-collapse
class="text-muted shadow-sm p-3 publisherCollaps"
>
<b-row v-b-toggle:my-collapse class="text-muted shadow-sm p-3 publisherCollaps">
<b-col>{{ $t('publisher.publisherId') }} {{ $store.state.publisherId }}</b-col>
<b-col class="text-right">
<b-icon icon="chevron-down" aria-hidden="true"></b-icon>

View File

@ -9,6 +9,7 @@ import { toastErrorSpy } from '@test/testSetup'
const localVue = global.localVue
const apolloMutationMock = jest.fn()
const apolloQueryMock = jest.fn().mockResolvedValue()
const routerPushMock = jest.fn()
@ -40,6 +41,7 @@ const mocks = {
},
$apollo: {
mutate: apolloMutationMock,
query: apolloQueryMock,
},
}

View File

@ -49,6 +49,7 @@
<script>
import InputPasswordConfirmation from '@/components/Inputs/InputPasswordConfirmation'
import { setPassword } from '@/graphql/mutations'
import { queryOptIn } from '@/graphql/queries'
const textFields = {
reset: {
@ -111,7 +112,22 @@ export default {
this.$router.push('/forgot-password/resetPassword')
})
},
checkOptInCode() {
this.$apollo
.query({
query: queryOptIn,
variables: {
optIn: this.$route.params.optin,
},
})
.then()
.catch((error) => {
this.toastError(error.message)
this.$router.push('/forgot-password/resetPassword')
})
},
setDisplaySetup() {
this.checkOptInCode()
if (this.$route.path.includes('checkEmail')) {
this.displaySetup = textFields.checkEmail
}

View File

@ -99,11 +99,11 @@ describe('Thx', () => {
})
it('renders the thanks redirect button', () => {
expect(wrapper.find('a.btn').text()).toBe('login')
expect(wrapper.find('a.btn').text()).toBe('settings.password.reset')
})
it('links the redirect button to /login', () => {
expect(wrapper.find('a.btn').attributes('href')).toBe('/login')
it('links the redirect button to /forgot-password', () => {
expect(wrapper.find('a.btn').attributes('href')).toBe('/forgot-password')
})
})
})

View File

@ -52,8 +52,8 @@ const textFields = {
login: {
headline: 'site.thx.errorTitle',
subtitle: 'site.thx.activateEmail',
button: 'login',
linkTo: '/login',
button: 'settings.password.reset',
linkTo: '/forgot-password',
},
}