func (serv AppService) ResetPassword(posted string) { user := User.User{} err := json.Unmarshal([]byte(posted), &user) if err != nil { fmt.Println(err.Error()) } else { fmt.Println(user.UserToJSON()) } userid := User.GetUserByEmail(user.Email) uuid, err := ReturnData.GenUUID() if err != nil { log.Fatal(err.Error()) } emailBody := "<p>Please click on the following link to reset your password. <a href=\"http://www.happenstance.me/reset/" emailBody += userid + "/" emailBody += uuid emailBody += "\"></p>" ReturnData.SendCustomMail(emailBody, "*****@*****.**", user.GetEmail(), "Reset Password @ happenStance.Me") }
func (serv AuthenticateService) LoginUser(posted string) { fmt.Println(posted) var str []string str = strings.Split(posted, "=") auth := Authenticate.Authenticate{} user := User.User{} err := json.Unmarshal([]byte(str[1]), &auth) if err != nil { log.Println(err.Error()) serv.ResponseBuilder().SetResponseCode(404).WriteAndOveride(nil) return } else { auth.Authorize() user.SetEmail(auth.Email) user.SetUserid(auth.User_id) serv.ResponseBuilder().SetResponseCode(200).Write([]byte(user.GetUser())) return } }
//*************User Service Methods *************** func (serv UserService) RegisterUser(posted string) { type newUser struct { Name string `json:"name" bson:"name"` Email string `json:"email" bson:"email"` Handle string `json:"handle" bson:"handle"` Password string `json:"password" bson:"password"` PhoneNumber string `json:"phone" bson:"phone"` } var data ReturnData.ReturnData var formData []string formData = strings.Split(posted, "=") user := User.User{} tempUser := newUser{} err := json.Unmarshal([]byte(formData[1]), &tempUser) if err != nil { log.Println(err.Error()) serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride(nil) return } else { user_id := User.CreateUserLogin(tempUser.Email, tempUser.Password) user.UserId, _ = strconv.Atoi(user_id) user.Name = tempUser.Name user.Email = tempUser.Email user.Handle = tempUser.Handle user.PhoneNumber = tempUser.PhoneNumber data = user.CreateUser() } if data.Success { serv.ResponseBuilder().SetResponseCode(201).Write([]byte(data.ToString())) } else { serv.ResponseBuilder().SetResponseCode(400).WriteAndOveride([]byte(data.ToString())) } }