Example #1
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
}
Example #2
0
func (this *exportApplication) fromDbApplication(form *db.ApplicationForm, isReviewer bool) {
	this.Timestamp = form.Timestamp

	this.Name = form.Name
	this.School = form.School
	this.Department = form.Department
	this.SchoolGrade = form.SchoolGrade
	this.Birthday = form.Birthday
	this.FormalId = form.FormalId
	this.Phone = form.Phone
	this.Email = form.Email
	this.Address = form.Address

	this.Topic = form.Topic
	this.Teacher = form.Teacher
	this.ResearchArea = form.ResearchArea
	this.ClassHistories = form.ClassHistories
	this.RelatedSkills = form.RelatedSkills
	this.AcademicGrade = form.AcademicGrade
	this.LangAbilities = form.LangAbilities

	//Hash
	this.Hash = public.NewSecureHashString()

	//Extras
	//Transform file id to url
	if client, err := storage.GetNewStorageClient(); err == nil {

		expireTime := time.Now().Add(time.Duration(1) * time.Hour) //an hour
		if obj, e := client.GetNewSignedURL(form.ResearchPlan, expireTime); e == nil {
			this.ResearchPlan = obj
		} else {
			public.LogE.Println("Get object error: " + e.Error())
		}
		if obj, e := client.GetNewSignedURL(form.Transcript, expireTime); e == nil {
			this.Transcript = obj
		} else {
			public.LogE.Println("Get object error: " + e.Error())
		}
		if len(form.Others) > 0 {
			if obj, e := client.GetNewSignedURL(form.Others, expireTime); e == nil {
				this.Others = obj
			} else {
				public.LogE.Println("Get object error: " + e.Error())
			}
		}
	} else {
		public.LogE.Printf("Error getting storage client")
	}

	appDb := public.GetNewApplicationDatabase()
	defer appDb.Session.Close()
	recomm := appDb.C(public.APPLICATION_DB_RECOMM_COLLECTION)
	var recommList []public.RecommResult

	for _, h := range form.Recommendations {
		//Transform recommendation from hash to structures
		q := recomm.Find(bson.M{
			"hash": h,
		})

		if n, e := q.Count(); e == nil && n > 0 {
			r := db.Recomm{}
			if e := q.One(&r); e == nil {
				r := public.RecommResult{
					Recommender: r.Recommender,
					ApplyUser:   r.ApplyUser,
					Done:        r.Submitted,
				}
				if isReviewer {
					r.Hash = h
				} else {
					r.Hash = ""
				}
				recommList = append(recommList, r)
			}
		}
	}
	this.Recommendations = recommList
}