SendActivationEmail function
(q bson.M)
| 37 | |
| 38 | // SendActivationEmail function |
| 39 | func (emailService *EmailService) SendActivationEmail(q bson.M) (success bool, err error) { |
| 40 | user := &models.User{} |
| 41 | var userService = UserService{} |
| 42 | q["active"] = false |
| 43 | err = userService.getCollection().First(q, user) |
| 44 | if err != nil { |
| 45 | return false, err |
| 46 | } |
| 47 | p, _ := rand.Prime(rand.Reader, 20) |
| 48 | user.ConfirmationToken = fmt.Sprintf("%d", p) |
| 49 | err = userService.getCollection().Update(user) |
| 50 | if err != nil { |
| 51 | return false, err |
| 52 | } |
| 53 | |
| 54 | engine := liquid.NewEngine() |
| 55 | emailModel, _ := loadEmail("activationLink", user.Language) |
| 56 | |
| 57 | bindings := map[string]interface{}{ |
| 58 | "email": user.Email, |
| 59 | "confirmationToken": user.ConfirmationToken, |
| 60 | } |
| 61 | result, err := engine.ParseAndRenderString(string(emailModel.Body), bindings) |
| 62 | |
| 63 | err = SendMail(os.Getenv("DEFAULT_EMAIL_FROM"), emailModel.Subject, result, []string{user.Email}) |
| 64 | return true, err |
| 65 | } |
| 66 | |
| 67 | // SendForgotPasswordEmail function |
| 68 | func (emailService *EmailService) SendForgotPasswordEmail(q bson.M) (success bool, err error) { |
no test coverage detected