コード例 #1
0
// @Title 修改密码
// @router /updatePassword [post]
func (this *APIStudentController) UpdatePassword() {
	//	recevie data
	if user_type := this.GetSession("type").(string); user_type != "学生" {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	id := this.GetSession("id").(string)
	if user, err := models.GetStudentById(id); err == nil {
		newpwd := this.GetString("newpwd")
		chkpwd := this.GetString("chkpwd")
		if newpwd != chkpwd {
			this.Redirect("/error", 302)
			this.StopRun()
		}
		if oldpwd := this.GetString("oldpwd"); user.Password == oldpwd {
			//	update pwd
			user.Password = newpwd
			if err := models.UpdateStudent(user); err != nil {
				this.Redirect("/error", 302)
				this.StopRun()
			}
			this.Redirect("/view/student/table?change=true", 302)
			this.StopRun()
		}
	}
	this.Redirect("/error", 302)
	this.StopRun()
}
コード例 #2
0
// @Title 登录教务系统
// @router /login [post]
func (this *APIStudentController) Login() {
	//	recevie data
	if user_type := this.GetSession("type").(string); user_type != "学生" {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	id := this.GetString("id")
	pwd := this.GetString("pwd")
	if len(id) <= 0 || len(pwd) <= 0 {
		this.Redirect("/view/student/login", 302)
		this.StopRun()
	}
	//	login edu
	if _, ok, _, _ := Edu.Sign_in(id, pwd, "学生"); !ok {
		this.Redirect("/view/student/login", 302)
		this.StopRun()
	}
	//	update student
	if user, err := models.GetStudentById(id); err == nil {
		user.EduPwd = pwd
		user.IsEdu = true
		if err := models.UpdateStudent(user); err == nil {
			this.Redirect("/view/student/eduLoading", 302)
			this.StopRun()
		}
	}
	this.Redirect("/view/student/login", 302)
	this.StopRun()
}
コード例 #3
0
// @Title 更新头像
// @router /updateImg [post]
func (this *APIStudentController) UpdateImg() {
	//	recevie data
	if user_type := this.GetSession("type").(string); user_type != "学生" {
		this.Redirect("/error", 302)
		this.StopRun()
	}
	id := this.GetSession("id").(string)
	if user, err := models.GetStudentById(id); err == nil {
		//	recevie the img
		user.Headimgurl = this.GetString("img")
		//	update student
		if err := models.UpdateStudent(user); err != nil {
			this.Redirect("/error", 302)
			this.StopRun()
		}
		this.Redirect("/view/student/table?change=true", 302)
		this.StopRun()
	}
	this.Redirect("/error", 302)
	this.StopRun()
}
コード例 #4
0
func UpdateStudentProfile(user *models.Student, userinfo map[string]string) error {
	if userinfo == nil {
		return models.ErrorInfo("UpdateStudentProfile", errors.New("userinfo is nil"))
	}
	if user == nil || user.Id != userinfo["学号"] {
		return models.ErrorInfo("UpdateStudentProfile", errors.New("用户与学号不匹配"))
	}
	user.Name = userinfo["姓名"]
	user.IsEdu = true
	if userinfo["性别"] == "男" {
		user.Sex = 1
	} else if userinfo["性别"] == "女" {
		user.Sex = 2
	}
	user.Headimgurl = userinfo["头像"]
	enterSchoolYear, _ := strconv.Atoi(userinfo["当前所在级"])
	user.EnterSchoolYear = enterSchoolYear
	enterSchoolDate, _ := strconv.Atoi(userinfo["入学日期"])
	user.EnterSchoolDate = enterSchoolDate
	idcard, _ := strconv.ParseInt(userinfo["身份证号"], 10, 64)
	user.IdCard = idcard

	if len(userinfo["系"]) > 0 {
		if exist := models.DepartmentExist(userinfo["系"]); !exist {
			_, err := models.AddDepartment(&models.Department{Name: userinfo["系"]})
			if err != nil {
				EduLogCreate(&EduLog{Student: user, Content: userinfo["系"], Type: "department", Result: 0})
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			EduLogCreate(&EduLog{Student: user, Content: userinfo["系"], Type: "department", Result: 1})
		}
	}
	if len(userinfo["专业名称"]) > 0 {
		if exist := models.MajorExist(userinfo["专业名称"]); !exist {
			department, err := models.GetDepartmentByName(userinfo["系"])
			if err != nil {
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			_, err = models.AddMajor(&models.Major{Name: userinfo["专业名称"], Department: department})
			if err != nil {
				EduLogCreate(&EduLog{Student: user, Content: userinfo["专业名称"], Type: "major", Result: 0})
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			EduLogCreate(&EduLog{Student: user, Content: userinfo["专业名称"], Type: "major", Result: 1})
		}
	}
	if len(userinfo["行政班"]) > 0 {
		if exist := models.ClassExist(userinfo["行政班"]); !exist {
			department, err := models.GetDepartmentByName(userinfo["系"])
			if err != nil {
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			major, err := models.GetMajorByName(userinfo["专业名称"])
			if err != nil {
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			_, err = models.AddClass(&models.Class{Name: userinfo["行政班"], Department: department, Major: major})
			if err != nil {
				EduLogCreate(&EduLog{Student: user, Content: userinfo["行政班"], Type: "class", Result: 0})
				return models.ErrorInfo("UpdateStudentProfile", err)
			}
			EduLogCreate(&EduLog{Student: user, Content: userinfo["行政班"], Type: "class", Result: 1})
		}
	}
	department, _ := models.GetDepartmentByName(userinfo["系"])
	major, _ := models.GetMajorByName(userinfo["专业名称"])
	class, _ := models.GetClassByName(userinfo["行政班"])
	user.Department = department
	user.Major = major
	user.Class = class
	if err := models.UpdateStudent(user); err != nil {
		return models.ErrorInfo("UpdateStudentProfile", err)
	}
	return nil
}