mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-19 05:55:19 +00:00
User fixes v4 (#168)
This commit is contained in:
@@ -53,13 +53,13 @@ func New(db db.DbService) *Domain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (domain *Domain) SendEmail(fromName, toAddress, toUsername, subject, textContent, token, redirctUrl string) error {
|
func (domain *Domain) SendEmail(fromName, toAddress, toUsername, subject, textContent, token, redirctUrl, failureRedirectUrl string) error {
|
||||||
if domain.sengridKey == "" {
|
if domain.sengridKey == "" {
|
||||||
return fmt.Errorf("empty email api key")
|
return fmt.Errorf("empty email api key")
|
||||||
}
|
}
|
||||||
from := mail.NewEmail(fromName, "support@m3o.com")
|
from := mail.NewEmail(fromName, "support@m3o.com")
|
||||||
to := mail.NewEmail(toUsername, toAddress)
|
to := mail.NewEmail(toUsername, toAddress)
|
||||||
textContent = strings.Replace(textContent, "$micro_verification_link", "https://angry-cori-854281.netlify.app?token="+token+"&redirectUrl="+url.QueryEscape(redirctUrl), -1)
|
textContent = strings.Replace(textContent, "$micro_verification_link", "https://angry-cori-854281.netlify.app?token="+token+"&redirectUrl="+url.QueryEscape(redirctUrl)+"&failureRedirectUrl="+url.QueryEscape(failureRedirectUrl), -1)
|
||||||
message := mail.NewSingleEmail(from, subject, to, textContent, "")
|
message := mail.NewSingleEmail(from, subject, to, textContent, "")
|
||||||
client := sendgrid.NewSendClient(domain.sengridKey)
|
client := sendgrid.NewSendClient(domain.sengridKey)
|
||||||
response, err := client.Send(message)
|
response, err := client.Send(message)
|
||||||
@@ -100,6 +100,9 @@ func (domain *Domain) DeleteSession(ctx context.Context, id string) error {
|
|||||||
|
|
||||||
// ReadToken returns the user id
|
// ReadToken returns the user id
|
||||||
func (domain *Domain) ReadToken(ctx context.Context, tokenId string) (string, error) {
|
func (domain *Domain) ReadToken(ctx context.Context, tokenId string) (string, error) {
|
||||||
|
if tokenId == "" {
|
||||||
|
return "", errors.New("token id empty")
|
||||||
|
}
|
||||||
token := &verificationToken{}
|
token := &verificationToken{}
|
||||||
|
|
||||||
rsp, err := domain.db.Read(ctx, &db.ReadRequest{
|
rsp, err := domain.db.Read(ctx, &db.ReadRequest{
|
||||||
@@ -110,7 +113,7 @@ func (domain *Domain) ReadToken(ctx context.Context, tokenId string) (string, er
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if len(rsp.Records) == 0 {
|
if len(rsp.Records) == 0 {
|
||||||
return "", errors.New("not found")
|
return "", errors.New("token not found")
|
||||||
}
|
}
|
||||||
m, _ := rsp.Records[0].MarshalJSON()
|
m, _ := rsp.Records[0].MarshalJSON()
|
||||||
json.Unmarshal(m, token)
|
json.Unmarshal(m, token)
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
|
|
||||||
"title": "Read account by email",
|
"title": "Read account by email",
|
||||||
"request": {
|
"request": {
|
||||||
"email": "joe@example.com"
|
"email": "joe@example.com"
|
||||||
@@ -52,5 +53,18 @@
|
|||||||
"updated": "1623677579"
|
"updated": "1623677579"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}],
|
||||||
|
"sendVerificationEmail": [{
|
||||||
|
"title": "Send verification email",
|
||||||
|
"request": {
|
||||||
|
"email": "joe@example.com",
|
||||||
|
"subject": "Email verification",
|
||||||
|
"redirectUrl": "https://m3o.com",
|
||||||
|
"failureRedirectUrl": "https://m3o.com/verification-failed",
|
||||||
|
"textContent": "Hi there,\n\nPlease verify your email by clicking this link: $micro_verification_link",
|
||||||
|
"fromName": "Awesome Dot Com"
|
||||||
|
},
|
||||||
|
"response": {
|
||||||
|
}
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,5 +212,5 @@ func (s *User) SendVerificationEmail(ctx context.Context, req *pb.SendVerificati
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.domain.SendEmail(req.FromName, req.Email, users[0].Username, req.Subject, req.TextContent, token, req.RedirectUrl)
|
return s.domain.SendEmail(req.FromName, req.Email, users[0].Username, req.Subject, req.TextContent, token, req.RedirectUrl, req.FailureRedirectUrl)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1128,11 +1128,12 @@ type SendVerificationEmailRequest struct {
|
|||||||
// The variable will be replaced with an actual url that will look similar to this:
|
// The variable will be replaced with an actual url that will look similar to this:
|
||||||
// 'https://user.m3o.com/user/verify?token=a-verification-token&rediretUrl=your-redir-url'
|
// 'https://user.m3o.com/user/verify?token=a-verification-token&rediretUrl=your-redir-url'
|
||||||
// HTML emails are not available currently.
|
// HTML emails are not available currently.
|
||||||
TextContent string `protobuf:"bytes,3,opt,name=textContent,proto3" json:"textContent,omitempty"`
|
TextContent string `protobuf:"bytes,3,opt,name=textContent,proto3" json:"textContent,omitempty"`
|
||||||
RedirectUrl string `protobuf:"bytes,4,opt,name=redirectUrl,proto3" json:"redirectUrl,omitempty"`
|
RedirectUrl string `protobuf:"bytes,4,opt,name=redirectUrl,proto3" json:"redirectUrl,omitempty"`
|
||||||
|
FailureRedirectUrl string `protobuf:"bytes,5,opt,name=failureRedirectUrl,proto3" json:"failureRedirectUrl,omitempty"`
|
||||||
// While the from email address can't be changed,
|
// While the from email address can't be changed,
|
||||||
// the from name (ie. sender name) can.
|
// the from name (ie. sender name) can.
|
||||||
FromName string `protobuf:"bytes,5,opt,name=fromName,proto3" json:"fromName,omitempty"`
|
FromName string `protobuf:"bytes,6,opt,name=fromName,proto3" json:"fromName,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SendVerificationEmailRequest) Reset() {
|
func (x *SendVerificationEmailRequest) Reset() {
|
||||||
@@ -1195,6 +1196,13 @@ func (x *SendVerificationEmailRequest) GetRedirectUrl() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *SendVerificationEmailRequest) GetFailureRedirectUrl() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.FailureRedirectUrl
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (x *SendVerificationEmailRequest) GetFromName() string {
|
func (x *SendVerificationEmailRequest) GetFromName() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.FromName
|
return x.FromName
|
||||||
@@ -1334,7 +1342,7 @@ var file_proto_user_proto_rawDesc = []byte{
|
|||||||
0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a,
|
0x79, 0x45, 0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a,
|
||||||
0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f,
|
0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f,
|
||||||
0x6b, 0x65, 0x6e, 0x22, 0x15, 0x0a, 0x13, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61,
|
0x6b, 0x65, 0x6e, 0x22, 0x15, 0x0a, 0x13, 0x56, 0x65, 0x72, 0x69, 0x66, 0x79, 0x45, 0x6d, 0x61,
|
||||||
0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xae, 0x01, 0x0a, 0x1c, 0x53,
|
0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0xde, 0x01, 0x0a, 0x1c, 0x53,
|
||||||
0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45,
|
0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45,
|
||||||
0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65,
|
0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65,
|
||||||
0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69,
|
0x6d, 0x61, 0x69, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69,
|
||||||
@@ -1344,7 +1352,10 @@ var file_proto_user_proto_rawDesc = []byte{
|
|||||||
0x52, 0x0b, 0x74, 0x65, 0x78, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x20, 0x0a,
|
0x52, 0x0b, 0x74, 0x65, 0x78, 0x74, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x12, 0x20, 0x0a,
|
||||||
0x0b, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x55, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01,
|
0x0b, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x55, 0x72, 0x6c, 0x18, 0x04, 0x20, 0x01,
|
||||||
0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x55, 0x72, 0x6c, 0x12,
|
0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x55, 0x72, 0x6c, 0x12,
|
||||||
0x1a, 0x0a, 0x08, 0x66, 0x72, 0x6f, 0x6d, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28,
|
0x2e, 0x0a, 0x12, 0x66, 0x61, 0x69, 0x6c, 0x75, 0x72, 0x65, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65,
|
||||||
|
0x63, 0x74, 0x55, 0x72, 0x6c, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x66, 0x61, 0x69,
|
||||||
|
0x6c, 0x75, 0x72, 0x65, 0x52, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x55, 0x72, 0x6c, 0x12,
|
||||||
|
0x1a, 0x0a, 0x08, 0x66, 0x72, 0x6f, 0x6d, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28,
|
||||||
0x09, 0x52, 0x08, 0x66, 0x72, 0x6f, 0x6d, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x1f, 0x0a, 0x1d, 0x53,
|
0x09, 0x52, 0x08, 0x66, 0x72, 0x6f, 0x6d, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x1f, 0x0a, 0x1d, 0x53,
|
||||||
0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45,
|
0x65, 0x6e, 0x64, 0x56, 0x65, 0x72, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x45,
|
||||||
0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x86, 0x05, 0x0a,
|
0x6d, 0x61, 0x69, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x86, 0x05, 0x0a,
|
||||||
|
|||||||
@@ -158,9 +158,10 @@ message SendVerificationEmailRequest{
|
|||||||
// HTML emails are not available currently.
|
// HTML emails are not available currently.
|
||||||
string textContent = 3;
|
string textContent = 3;
|
||||||
string redirectUrl = 4;
|
string redirectUrl = 4;
|
||||||
|
string failureRedirectUrl = 5;
|
||||||
// While the from email address can't be changed,
|
// While the from email address can't be changed,
|
||||||
// the from name (ie. sender name) can.
|
// the from name (ie. sender name) can.
|
||||||
string fromName = 5;
|
string fromName = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message SendVerificationEmailResponse{}
|
message SendVerificationEmailResponse{}
|
||||||
Reference in New Issue
Block a user