Exemple #1
0
func SaveBlog(ctx *middleware.Context, blog model.Blog) {
	if blog.Title == "" || blog.Content == "" {
		ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.save.failed"))
	} else {
		tags := ctx.R.PostForm["tags"]
		blog.SetTags(tags)
		signedUser := ctx.S.Get("SignedUser").(model.User)
		blog.UpdateUser = signedUser.Username
		if blog.Version == 0 {
			blog.State = "DRAFT"
			blog.Priority = 5
			blog.Author = signedUser
			blog.CreateUser = signedUser.Username
			err := blog.Insert()
			PanicIf(err)
		} else {
			err := blog.Update()
			PanicIf(err)
		}
		dbBlog, err := blog.GetBlogById()
		PanicIf(err)
		ctx.Set("Blog", dbBlog)

		ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.save.success"))
	}

	tags, err := blog.GetAllTags()
	PanicIf(err)
	ctx.Set("Tags", tags)

	ctx.HTML(200, "blog/edit", ctx)
}
Exemple #2
0
func PasswordHandler(ctx *middleware.Context, formErr binding.Errors, password model.Password) {
	switch ctx.R.Method {
	case "POST":
		ctx.JoinFormErrors(formErr)
		if !ctx.HasError() {
			if password.CurrentPassword == password.ConfirmPassword {
				ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.password.not.changed"))
			} else {
				user := &model.User{Id: password.Id}
				dbUser, err := user.GetUserById(user.Id)
				PanicIf(err)
				if dbUser.Password == Md5(password.CurrentPassword) {
					dbUser.Password = Md5(password.ConfirmPassword)
					err := dbUser.Update()
					PanicIf(err)
					ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
				} else {
					ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.wrong.password"))
				}
			}
		}
	default:
	}
	ctx.HTML(200, "profile/password", ctx)
}
Exemple #3
0
func PublishBlog(ctx *middleware.Context, blog model.Blog) {
	switch ctx.R.Method {
	case "POST":
		if blog.Title == "" || blog.Content == "" {
			ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.publish.failed"))
		} else {
			tags := ctx.R.PostForm["tags"]
			blog.SetTags(tags)
			signedUser := ctx.S.Get("SignedUser").(model.User)
			blog.State = "PUBLISHED"
			blog.PublishDate = time.Now()
			if blog.Version == 0 {
				blog.Priority = 5
				blog.Author = signedUser
				blog.CreateUser = signedUser.Username
				err := blog.Insert()
				PanicIf(err)
			} else {
				err := blog.Update()
				PanicIf(err)
			}
		}
		ctx.Redirect("/blog/view/" + IntString(blog.Id))
	default:
		tags, err := blog.GetAllTags()
		PanicIf(err)
		ctx.Set("Tags", tags)

		ctx.HTML(200, "blog/edit", ctx)
	}
}
Exemple #4
0
func EditLink(ctx *middleware.Context, params martini.Params) {
	id := params["id"]
	link := new(model.Link)
	link.Id = ParseInt(id)
	err := link.GetLink()
	PanicIf(err)
	ctx.Set("Link", link)

	ctx.HTML(200, "link/edit", ctx)
}
Exemple #5
0
func ContactHandler(ctx *middleware.Context, feedback model.Feedback) {
	switch ctx.R.Method {
	case "POST":
		err := feedback.Insert()
		PanicIf(err)
		ctx.Set("success", true)
		ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.send.success"))
		ctx.JSON(200, ctx.Response)
	default:
		ctx.HTML(200, "contact", ctx)
	}
}
Exemple #6
0
func InsertLink(ctx *middleware.Context, link model.Link) {
	switch ctx.R.Method {
	case "POST":
		err := link.Insert()
		PanicIf(err)
		ctx.Set("success", true)
		ctx.Set("message", Translate(ctx.S.Get("Lang").(string), "message.send.success"))
		ctx.Redirect("/link/all")
	default:
		ctx.HTML(200, "link/edit", ctx)
	}
}
Exemple #7
0
func LoginHandler(ctx *middleware.Context, formErr binding.Errors, loginUser model.UserLoginForm) {
	switch ctx.R.Method {
	case "POST":
		ctx.JoinFormErrors(formErr)
		password := Md5(loginUser.Password)
		user := &model.User{Username: loginUser.Username, Password: password}
		if !ctx.HasError() {
			if has, err := user.Exist(); has {
				PanicIf(err)
				if user.Locked {
					ctx.Set("User", user)
					ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.invalid.username.or.password"))
					ctx.HTML(200, "user/login", ctx)
					return
				}
				ctx.S.Set("SignedUser", user)
				Log.Info(user.Username, " login")
				ctx.Redirect("/admin/dashboard")
			} else {
				ctx.Set("User", user)
				ctx.AddError(Translate(ctx.S.Get("Lang").(string), "message.error.invalid.username.or.password"))
				ctx.HTML(200, "user/login", ctx)
			}
		} else {
			ctx.HTML(200, "user/login", ctx)
		}
	default:
		ctx.HTML(200, "user/login", ctx)
	}
}
Exemple #8
0
func EditBlog(ctx *middleware.Context, params martini.Params) {
	id := params["id"]
	blog := new(model.Blog)
	blog.Id = ParseInt(id)
	err := blog.GetBlog()
	PanicIf(err)
	ctx.Set("Blog", blog)

	tags, err := blog.GetAllTags()
	PanicIf(err)
	ctx.Set("Tags", tags)

	ctx.HTML(200, "blog/edit", ctx)
}
Exemple #9
0
func SettingsHandler(ctx *middleware.Context, settings model.Settings) {
	if ctx.R.Method == "POST" {
		err := settings.Update()
		PanicIf(err)
		dbSettings := model.GetSettings()
		ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
		ctx.S.Set("Settings", dbSettings)
	}
	user := &model.User{}
	users, err := user.SelectAll()
	PanicIf(err)
	ctx.Set("Users", users)

	ctx.HTML(200, "admin/settings", ctx)
}
Exemple #10
0
func DashboardHandler(ctx *middleware.Context) {
	visit := new(model.Visit)
	visit.SetPageActive(true)
	visit.SetPageSize(10)
	pageNo := ParseInt(ctx.R.FormValue("page"))
	visit.SetPageNo(pageNo)
	visit.AddSortProperty("create_date", "desc")
	visitList, total, err := visit.SearchByPage()
	PanicIf(err)

	visit.SetTotalRecord(total)
	visit.Result = visitList
	ctx.Set("Visit", visit)
	ctx.HTML(200, "admin/dashboard", ctx)
}
Exemple #11
0
func ProfileHandler(ctx *middleware.Context, formErr binding.Errors, user model.User) {
	switch ctx.R.Method {
	case "POST":
		ctx.JoinFormErrors(formErr)
		if !ctx.HasError() {
			err := user.Update()
			PanicIf(err)
			dbUser, err := user.GetUserById(user.Id)
			PanicIf(err)
			ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.change.success"))
			ctx.S.Set("SignedUser", dbUser)
		}
		ctx.HTML(200, "profile/profile", ctx)
	default:
		ctx.HTML(200, "profile/profile", ctx)
	}
}
Exemple #12
0
func AllFeedback(ctx *middleware.Context) {
	switch ctx.R.Method {
	case "POST":
		feedback := new(model.Feedback)
		feedback.SetPageActive(true)
		feedback.SetPageSize(ParseInt(ctx.R.FormValue("iDisplayLength")))
		feedback.SetDisplayStart(ParseInt(ctx.R.FormValue("iDisplayStart")))
		columnNum := ctx.R.FormValue("iSortCol_0")
		sortColumn := ctx.R.FormValue("mDataProp_" + columnNum)
		feedback.AddSortProperty(sortColumn, ctx.R.FormValue("sSortDir_0"))
		feedbackArray, total, err := feedback.SearchByPage()
		PanicIf(err)
		ctx.Set("aaData", feedbackArray)
		ctx.Set("iTotalDisplayRecords", total)
		ctx.Set("iTotalRecords", total)
		ctx.JSON(200, ctx.Response)
	default:
		ctx.HTML(200, "feedback/allFeedback", ctx)
	}
}
Exemple #13
0
func AllUserHandler(ctx *middleware.Context) {
	switch ctx.R.Method {
	case "POST":
		user := new(model.User)
		user.SetPageActive(true)
		user.SetPageSize(ParseInt(ctx.R.FormValue("iDisplayLength")))
		user.SetDisplayStart(ParseInt(ctx.R.FormValue("iDisplayStart")))
		columnNum := ctx.R.FormValue("iSortCol_0")
		sortColumn := ctx.R.FormValue("mDataProp_" + columnNum)
		user.AddSortProperty(sortColumn, ctx.R.FormValue("sSortDir_0"))
		users, total, err := user.SearchByPage()
		PanicIf(err)
		ctx.Set("aaData", users)
		ctx.Set("iTotalDisplayRecords", total)
		ctx.Set("iTotalRecords", total)
		ctx.JSON(200, ctx.Response)
	default:
		ctx.HTML(200, "user/allUser", ctx)
	}
}
Exemple #14
0
func AllBlog(ctx *middleware.Context) {
	switch ctx.R.Method {
	case "POST":
		blog := new(model.Blog)
		blog.SetPageActive(true)
		blog.SetPageSize(ParseInt(ctx.R.FormValue("iDisplayLength")))
		blog.SetDisplayStart(ParseInt(ctx.R.FormValue("iDisplayStart")))
		columnNum := ctx.R.FormValue("iSortCol_0")
		sortColumn := ctx.R.FormValue("mDataProp_" + columnNum)
		blog.AddSortProperty(sortColumn, ctx.R.FormValue("sSortDir_0"))
		blogList, total, err := blog.SearchByPage(false)
		PanicIf(err)
		ctx.Set("aaData", blogList)
		ctx.Set("iTotalDisplayRecords", total)
		ctx.Set("iTotalRecords", total)
		ctx.JSON(200, ctx.Response)
	default:
		ctx.HTML(200, "blog/allBlog", ctx)
	}
}
Exemple #15
0
func Blog(ctx *middleware.Context) {
	blog := new(model.Blog)
	blog.SetPageActive(true)
	blog.SetPageSize(10)
	pageNo := ParseInt(ctx.R.FormValue("page"))
	blog.SetPageNo(pageNo)
	blog.State = "PUBLISHED"
	blog.AddSortProperty("publish_date", "desc")
	blogList, total, err := blog.SearchByPage(true)
	PanicIf(err)

	blog.SetTotalRecord(total)
	blog.Result = blogList
	ctx.Set("Blog", blog)

	tags, err := blog.GetAllTags()
	PanicIf(err)
	ctx.Set("Tags", tags)

	ctx.HTML(200, "blog", ctx)
}
Exemple #16
0
func RegisterHandler(ctx *middleware.Context, formErr binding.Errors, user model.UserRegisterForm) {
	switch ctx.R.Method {
	case "POST":
		ctx.JoinFormErrors(formErr)
		if !ctx.HasError() {
			dbUser := model.User{Username: user.Username, Password: user.Password, Email: user.Email}

			if exist, err := dbUser.ExistUsername(); exist {
				PanicIf(err)
				ctx.AddFieldError("username", Translate(ctx.S.Get("Lang").(string), "message.error.already.exists"))
			}

			if exist, err := dbUser.ExistEmail(); exist {
				PanicIf(err)
				ctx.AddFieldError("email", Translate(ctx.S.Get("Lang").(string), "message.error.already.exists"))
			}

			if !ctx.HasError() {
				dbUser.Password = Md5(user.Password)
				err := dbUser.Insert()
				PanicIf(err)
				ctx.AddMessage(Translate(ctx.S.Get("Lang").(string), "message.register.success"))
			} else {
				ctx.Set("User", user)
			}
			ctx.HTML(200, "user/register", ctx)
		} else {
			ctx.Set("User", user)
			ctx.HTML(200, "user/register", ctx)
		}
	default:
		ctx.HTML(200, "user/register", ctx)
	}
}
Exemple #17
0
func About(ctx *middleware.Context) {
	ctx.HTML(200, "about", ctx)
}
Exemple #18
0
func Index(ctx *middleware.Context) {
	ctx.HTML(200, "index", ctx)
}
Exemple #19
0
func PreferencesHandler(ctx *middleware.Context) {
	ctx.HTML(200, "profile/preferences", ctx)
}