// @Tilte 查看教师资料 // @router /teacherInfo [get] func (this *ViewStudentController) TeacherInfo() { if teacher_id, err := this.GetInt64("teacher"); err == nil { if teacher, err := models.GetTeacherById(teacher_id); err == nil { teacher.Profile, _ = models.GetTeacherProfile(teacher_id) this.Data["teacher"] = teacher } else { this.Redirect("/error", 302) this.StopRun() } } else { this.Redirect("/error", 302) this.StopRun() } this.Layout = "student/base.html" this.TplNames = "student/teacherInfo.html" }
func (this *ViewTeatherController) Prepare() { // get session user_type := this.GetSession("type").(string) if user_type == "教师" { id := this.GetSession("id").(string) if len(id) > 0 { if t_id, err := strconv.ParseInt(id, 10, 64); err == nil { teacher, err := models.GetTeacherById(t_id) if err == nil { this.Data["teacher"] = teacher // 设置操作签名,获取签名参数 appid, sessid := this.SetSignature() this.Data["appid"] = appid this.Data["sessid"] = sessid this.Data["key"] = models.Str2Sha1(this.Ctx.Input.Cookie("beegosessionID")) return } } } } this.Redirect("/error", 302) this.StopRun() }
// @Title 登录验证 // @router /index [post] func (this *ViewController) Login() { // recevie the login key login_key := this.GetString("login_key") if len(login_key) <= 0 && login_key != models.Str2Sha1(this.Ctx.Input.Cookie("beegosessionID")) { this.Redirect("/index", 302) this.StopRun() } account := this.GetString("account") pwd := this.GetString("pwd") user_type := this.GetString("type") // 植入cookie token := fmt.Sprintf("%d", models.GetMathRand(10240)) this.Ctx.SetCookie("token", token, 3600) if this.GetSession("token") != nil { this.DelSession("token") } this.SetSession("token", token) switch user_type { case "学生": edu := this.GetString("edu") if edu == "on" { if !models.StudentExist(account) { if data, ok, cookies, _ := Edu.Sign_in(account, pwd, user_type); ok { if _, err := Edu.GetStudentProfile(data, cookies); err == nil { if err = models.AddStudent(&models.Student{Id: account, EduPwd: pwd}); err == nil { // 设置session if this.GetSession("id") != nil { this.DelSession("id") } this.SetSession("id", account) if this.GetSession("type") != nil { this.DelSession("type") } this.SetSession("type", user_type) this.Redirect("/view/student/eduLoading", 302) this.StopRun() } } } } else { user, err := models.GetStudentById(account) if err == nil { if user.EduPwd == pwd { // 设置session if this.GetSession("id") != nil { this.DelSession("id") } this.SetSession("id", account) if this.GetSession("type") != nil { this.DelSession("type") } this.SetSession("type", user_type) // login success this.Redirect("/view/student/table", 302) this.StopRun() } } } } if models.StudentExist(account) == true { user, err := models.GetStudentById(account) if err == nil { if user.Password == pwd { // 设置session if this.GetSession("id") != nil { this.DelSession("id") } this.SetSession("id", account) if this.GetSession("type") != nil { this.DelSession("type") } this.SetSession("type", user_type) // login success this.Redirect("/view/student/table", 302) this.StopRun() } } } case "教师": id, _ := strconv.ParseInt(account, 10, 64) if models.TeacherExist(id) == true { user, err := models.GetTeacherById(id) if err == nil { if user.Password == pwd { // 设置session if this.GetSession("id") != nil { this.DelSession("id") } this.SetSession("id", account) if this.GetSession("type") != nil { this.DelSession("type") } this.SetSession("type", user_type) // login success this.Redirect("/view/teacher/table", 302) this.StopRun() } } } case "教务": if models.AdminExist(account) == true { user, err := models.GetAdminById(account) if err == nil { if user.Password == pwd { // 设置session if this.GetSession("id") != nil { this.DelSession("id") } this.SetSession("id", account) if this.GetSession("type") != nil { this.DelSession("type") } this.SetSession("type", user_type) // login success this.Redirect("/view/admin/index", 302) this.StopRun() } } } } this.Redirect("/", 302) this.StopRun() }