예제 #1
0
// @Title 上传头像
// @router /uploadImg [post]
func (this *APIStudentController) UploadImg() {
	//	recevie data
	if user_type := this.GetSession("type").(string); user_type != "学生" {
		this.SendFailedJSON(1, "操作失败")
		return
	}
	//	recevie the img
	path := "UPLOADS/headimg/"
	models.CreateDir(path)
	filepath := path + models.GetRandString(2014) + ".jpeg"
	if err := this.SaveToFile("img", filepath); err != nil {
		this.SendFailedJSON(1, "操作失败")
		return
	}
	this.SendSuccessJSON("/" + filepath)
	return
}
예제 #2
0
// @Title 学生上传作业
// @router /uploadAttachment [post]
func (this *APIStudentController) UploadAttachment() {
	//	recevie data
	if user_type := this.GetSession("type").(string); user_type != "学生" {
		this.SendFailedJSON(1, "操作失败")
		return
	}
	if s_homework_id, err := this.GetInt64("student_homework"); err == nil {
		if s_homework, err := models.GetStudentHomeworkById(s_homework_id); err == nil {
			if s_homework.Student.Id != this.GetSession("id").(string) {
				this.SendFailedJSON(1, "用户不匹配")
				return
			}
			if time.Now().After(models.GetTime(s_homework.TeacherCourseHomework.AsOfTime)) {
				this.SendFailedJSON(1, "已经截止提交")
				return
			}
			//	get attachment
			path := "UPLOADS/homework/"
			models.CreateDir(path)
			filepath := path + models.GetRandString(2014) + ".zip"
			if err := this.SaveToFile("attachment", filepath); err != nil {
				this.SendFailedJSON(1, err)
				return
			}
			s_homework.Attachment = "/" + filepath
			s_homework.IsUpload = 1
			if err := models.UpdateStudentHomework(s_homework); err == nil {
				this.SendSuccessJSON("操作成功")
				return
			} else {
				this.SendFailedJSON(1, "更新学生作业失败")
				return
			}
		} else {
			this.SendFailedJSON(1, "获取学生作业失败")
			return
		}

	} else {
		this.SendFailedJSON(1, "获取学生作业id失败")
		return
	}
	this.SendFailedJSON(1, "操作失败")
	return
}