-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemail.go
More file actions
42 lines (37 loc) · 966 Bytes
/
email.go
File metadata and controls
42 lines (37 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2012 The AEGo Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package user
import (
"appengine"
"errors"
"github.com/gaego/user/email"
)
var (
ErrKeyNotSet = errors.New("user: key not set")
)
// AddEmail appends the email to the User's emails. Returns true if role
// was added.
func (u *User) AddEmail(c appengine.Context, address string, status int64) (e *email.Email, err error) {
if u.Key.StringID() == "" {
return nil, ErrKeyNotSet
}
if u.HasEmail(address) {
return nil, email.ErrAddressAlreadyAdded
}
e, err = email.AddForUser(c, address, u.Key.StringID(), status)
if err != nil {
return e, err
}
u.Emails = append(u.Emails, address)
return e, nil
}
// HasEmail returns true if the user has the email.
func (u *User) HasEmail(address string) bool {
for _, a := range u.Emails {
if a == address {
return true
}
}
return false
}