satellite/console: email used error handling for registration

Change-Id: Ifd3f2ce065ebd3c5e538c5c1eeaa76137b243b78
This commit is contained in:
VitaliiShpital 2020-03-26 17:35:14 +02:00 committed by Vitalii Shpital
parent 506582e208
commit 23da9228b3
6 changed files with 24 additions and 6 deletions

View File

@ -395,6 +395,8 @@ func (a *Auth) getStatusCode(err error) int {
return http.StatusBadRequest return http.StatusBadRequest
case console.ErrUnauthorized.Has(err): case console.ErrUnauthorized.Has(err):
return http.StatusUnauthorized return http.StatusUnauthorized
case console.ErrEmailUsed.Has(err):
return http.StatusConflict
default: default:
return http.StatusInternalServerError return http.StatusInternalServerError
} }

View File

@ -431,7 +431,7 @@ func (s *Service) CreateUser(ctx context.Context, user CreateUser, tokenSecret R
u, err = s.store.Users().GetByEmail(ctx, user.Email) u, err = s.store.Users().GetByEmail(ctx, user.Email)
if err == nil { if err == nil {
return nil, errs.New(emailUsedErrMsg) return nil, ErrEmailUsed.New(emailUsedErrMsg)
} }
if err != sql.ErrNoRows { if err != sql.ErrNoRows {
return nil, Error.Wrap(err) return nil, Error.Wrap(err)

View File

@ -1,6 +1,7 @@
// Copyright (C) 2019 Storj Labs, Inc. // Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information. // See LICENSE for copying information.
import { ErrorEmailUsed } from '@/api/errors/ErrorEmailUsed';
import { ErrorUnauthorized } from '@/api/errors/ErrorUnauthorized'; import { ErrorUnauthorized } from '@/api/errors/ErrorUnauthorized';
import { UpdatedUser, User } from '@/types/users'; import { UpdatedUser, User } from '@/types/users';
import { HttpClient } from '@/utils/httpClient'; import { HttpClient } from '@/utils/httpClient';
@ -200,11 +201,14 @@ export class AuthHttpApi {
const response = await this.http.post(path, JSON.stringify(body)); const response = await this.http.post(path, JSON.stringify(body));
if (!response.ok) { if (!response.ok) {
if (response.status === 401) { switch (response.status) {
throw new ErrorUnauthorized('we are unable to create your account. This is an invite-only alpha, please join our waitlist to receive an invitation'); case 401:
throw new ErrorUnauthorized('We are unable to create your account. This is an invite-only alpha, please join our waitlist to receive an invitation');
case 409:
throw new ErrorEmailUsed('This email is already in use, try another');
default:
throw new Error('Can not register user');
} }
throw new Error('can not register user');
} }
return await response.json(); return await response.json();

View File

@ -0,0 +1,11 @@
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
/**
* ErrorEmailUsed is a custom error type for performing 'email is already in use' operations.
*/
export class ErrorEmailUsed extends Error {
public constructor(message: string = 'email used') {
super(message);
}
}

View File

@ -23,7 +23,7 @@
<div class="header-default-state" v-if="isDefaultHeaderState"> <div class="header-default-state" v-if="isDefaultHeaderState">
<VButton <VButton
class="button" class="button"
label="+Create API Key" label="+ Create API Key"
width="180px" width="180px"
height="48px" height="48px"
:on-press="onCreateApiKeyClick" :on-press="onCreateApiKeyClick"

View File

@ -96,6 +96,7 @@ export default class VButton extends Vue {
font-size: 16px; font-size: 16px;
line-height: 23px; line-height: 23px;
color: #fff; color: #fff;
margin: 0;
} }
&:hover { &:hover {