예제 #1
0
func (t *Teacher) AddDoc(db *mgo.Database) utils.Response {

	/**
	Hash the password
	*/
	t.Password = utils.HashPassword(t.Password)

	var teachers []Teacher
	/*
		Dangerous way improvemtn required
	*/
	err := db.C(teacherCollectionName).Find(bson.M{
		"username": t.Username,
	}).All(&teachers)

	if err != nil || len(teachers) > 0 {
		return utils.Response{true, "Already exist"}
	} else {
		err1 := db.C(teacherCollectionName).Insert(t)

		if err1 != nil {
			return utils.Response{true, "Error ro"}
		} else {
			return utils.Response{false, "Inserted"}
		}
	}
}
예제 #2
0
func (s *Student) CheckUserPassword(db *mgo.Database) (Student, error) {
	s.Password = utils.HashPassword(s.Password)

	var stud Student
	err := db.C(studentCollectionName).Find(bson.M{
		"username": s.Username,
		"password": s.Password,
	}).One(&stud)

	return stud, err
}
예제 #3
0
func (t *Teacher) GetByUsernameAndPassword(db *mgo.Database) Teacher {

	t.Password = utils.HashPassword(t.Password)

	var tempTeacher Teacher
	err := db.C(teacherCollectionName).
		Find(bson.M{
			"username": t.Username,
			"password": t.Password,
		}).
		One(&tempTeacher)

	if err != nil {
		log.Print("Coming", t.Username, t.Password)
		log.Print("Error in query", err)
		return tempTeacher
	} else {
		return tempTeacher
	}
}
예제 #4
0
func (s *Student) NewUser(db *mgo.Database) error {
	s.Password = utils.HashPassword(s.Password)
	return db.C(studentCollectionName).Insert(s)
}