예제 #1
0
func handleGMRecommsResend(resp http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	hash := vars["recommHash"]

	appDb := public.GetNewApplicationDatabase()
	defer appDb.Session.Close()

	recomm := appDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
	q := recomm.Find(bson.M{
		"hash": hash,
	})
	recommObj := db.Recomm{}
	if err := q.One(&recommObj); err != nil || len(hash) <= 0 {
		public.ResponseStatusAsJson(resp, 404, &public.SimpleResult{
			Message:     "Error",
			Description: "No Such page",
		})
		return
	}

	url := "https://application.nthuaplus.org/recomm.html?hash=" + hash
	if e := public.SendMail(recommObj.Recommender.Email, recommObj.ApplyUser, url); e != nil {
		public.LogE.Printf("Error sending email: %s\n", e.Error())
		public.ResponseStatusAsJson(resp, 500, &public.SimpleResult{
			Message: "Error",
		})
	} else {
		public.ResponseOkAsJson(resp, nil)
	}
}
예제 #2
0
func handleRecommendationLetters(letters []public.BasicUser, name, email string) []string {
	var hashList []string

	appDb := public.GetNewApplicationDatabase()
	defer appDb.Session.Close()

	recomm := appDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
	for _, l := range letters {
		r := db.Recomm{

			Hash: public.NewSecureHashString(),

			Submitted: false,

			ApplyUser: public.BasicUser{
				Name:  name,
				Email: email,
			},
			Recommender: public.BasicUser{
				Name:  l.Name,
				Email: l.Email,
			},
		}
		if e := recomm.Insert(&r); e != nil {
			public.LogE.Printf("Failed inserting recommendation entity for applyer %s", name)
		} else {
			hashList = append(hashList, r.Hash)

			url := "https://application.nthuaplus.org/recomm.html?hash=" + r.Hash

			applier := r.ApplyUser
			applier.Name = public.ConvertName(applier.Name)
			if e := public.SendMail(l.Email, applier, url); e != nil {
				public.LogE.Println("Error sending email to " + l.Email + ": " + e.Error())
			}
		}
	}

	return hashList
}