Skip to content

Commit 2182421

Browse files
committed
have separate email field as well
1 parent 766add9 commit 2182421

File tree

7 files changed

+70
-2
lines changed

7 files changed

+70
-2
lines changed

frontend/pages/AccountPage.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
AccountChangeDescription,
2121
AccountChangeUrl,
2222
AccountChangeUsername,
23+
AccountChangeEmail,
2324
AccountDelete,
2425
AccountDeleteSecret,
2526
AccountRename,
@@ -306,6 +307,22 @@ export default class AccountPage extends React.Component<AccountPageProps, Accou
306307
<ClipboardButton text={account.Username} />
307308
</td>
308309
</tr>
310+
<tr>
311+
<th>
312+
Email
313+
<span className="margin-left">
314+
<CommandIcon
315+
command={AccountChangeEmail(account.Id, account.Email)}
316+
/>
317+
</span>
318+
</th>
319+
<td>
320+
<OptionalContent>{account.Email}</OptionalContent>
321+
</td>
322+
<td>
323+
<ClipboardButton text={account.Email} />
324+
</td>
325+
</tr>
309326
{secretRows}
310327
<tr>
311328
<th>

pkg/apitypes/commands.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@
3232
{ "key": "Username", "optional": true }
3333
]
3434
},
35+
{
36+
"command": "account.ChangeEmail",
37+
"chain": "authenticated",
38+
"ctor": ["Account","Email"],
39+
"crudNature": "update",
40+
"title": "Change email",
41+
"fields": [
42+
{ "key": "Account", "hideIfDefaultValue": true },
43+
{ "key": "Email", "placeholder": "bob@example.com", "optional": true }
44+
]
45+
},
3546
{
3647
"command": "account.ChangeDescription",
3748
"chain": "authenticated",
@@ -119,6 +130,7 @@
119130
{ "key": "Title", "placeholder": "Reddit", "optional": true, "help": "If you don`t specify this, then URL is required" },
120131
{ "key": "Url", "placeholder": "https://www.reddit.com/", "title": "URL", "optional": true, "help": "If you don`t specify this, then Title is required" },
121132
{ "key": "Username", "placeholder": "bob@example.com", "optional": true },
133+
{ "key": "Email", "optional": true, "help": "If your account has username AND email, specify it here. If the account uses email as username, then write email in username." },
122134
{ "key": "Password", "type": "password", "optional": true },
123135
{ "key": "PasswordRepeat", "placeholder": "(optional, to prevent typos)", "title": "Repeat password", "type": "password", "optional": true }
124136
]

pkg/apitypes/types.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"Created": {"_": "datetime"},
4343
"FolderId": {"_": "string"},
4444
"Title": {"_": "string"},
45+
"Email": {"_": "string"},
4546
"Url": {"_": "string"},
4647
"Username": {"_": "string"},
4748
"Description": {"_": "string"}

pkg/commands/handlers.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ func (h *Handlers) AccountChangeUsername(a *apitypes.AccountChangeUsername, ctx
8787
return nil
8888
}
8989

90+
func (h *Handlers) AccountChangeEmail(a *apitypes.AccountChangeEmail, ctx *command.Ctx) error {
91+
if h.userData(ctx).WrappedAccountById(a.Account) == nil {
92+
return errAccountNotFound
93+
}
94+
95+
ctx.RaisesEvent(domain.NewAccountEmailChanged(
96+
a.Account,
97+
a.Email,
98+
ctx.Meta))
99+
100+
return nil
101+
}
102+
90103
func (h *Handlers) AccountChangeUrl(a *apitypes.AccountChangeUrl, ctx *command.Ctx) error {
91104
if h.userData(ctx).WrappedAccountById(a.Account) == nil {
92105
return errAccountNotFound
@@ -227,6 +240,13 @@ func (h *Handlers) AccountCreate(a *apitypes.AccountCreate, ctx *command.Ctx) er
227240
ctx.Meta))
228241
}
229242

243+
if a.Email != "" {
244+
ctx.RaisesEvent(domain.NewAccountEmailChanged(
245+
accountId,
246+
a.Email,
247+
ctx.Meta))
248+
}
249+
230250
if a.Password != "" {
231251
// if PasswordRepeat given, verify it
232252
if err := verifyRepeatPassword(a.Password, a.PasswordRepeat); a.PasswordRepeat != "" && err != nil {

pkg/domain/events.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@
232232
}
233233
]
234234
},
235+
{
236+
"event": "account.EmailChanged",
237+
"ctor": ["Id", "Email"],
238+
"fields": [
239+
{
240+
"key": "Id", "type": {"_": "string"}
241+
},
242+
{
243+
"key": "Email", "type": {"_": "string"}
244+
}
245+
]
246+
},
235247
{
236248
"event": "account.FolderCreated",
237249
"ctor": ["Id", "ParentId", "Name"],

pkg/state/userstate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ func (l *UserStorage) processEvent(ev ehevent.Event) error {
209209
}
210210
case *domain.AccountUsernameChanged:
211211
l.accounts[e.Id].Account.Username = e.Username
212+
case *domain.AccountEmailChanged:
213+
l.accounts[e.Id].Account.Email = e.Email
212214
case *domain.AccountUrlChanged:
213215
l.accounts[e.Id].Account.Url = e.Url
214216
case *domain.AccountRenamed:

pkg/state/userstate_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,23 @@ func addAccount(t *testing.T, tc *testContext) {
236236
domain.NewAccountUrlChanged(testAccId, "https://google.com/", ehevent.Meta(t0, joonasUid)))
237237

238238
tc.appendAndLoad(
239-
domain.NewAccountUsernameChanged(testAccId, "joonas@example.com", ehevent.Meta(t0, joonasUid)))
239+
domain.NewAccountUsernameChanged(testAccId, "joonas.fi", ehevent.Meta(t0, joonasUid)))
240+
241+
tc.appendAndLoad(
242+
domain.NewAccountEmailChanged(testAccId, "joonas@example.com", ehevent.Meta(t0, joonasUid)))
240243

241244
tc.appendAndLoad(
242245
domain.NewAccountDescriptionChanged(testAccId, "Notes for account\nLine 2", ehevent.Meta(t0, joonasUid)))
243246

244247
assert.EqualJson(t, tc.user.accounts[testAccId].Account, `{
245248
"Created": "2020-02-20T14:02:00Z",
246249
"Description": "Notes for account\nLine 2",
250+
"Email": "joonas@example.com",
247251
"FolderId": "root",
248252
"Id": "accId1",
249253
"Title": "google.com",
250254
"Url": "https://google.com/",
251-
"Username": "joonas@example.com"
255+
"Username": "joonas.fi"
252256
}`)
253257
}
254258

0 commit comments

Comments
 (0)