Example #1
0
//Post Page
func (this *SinglePost) Get() error {
	var postMd models.Post
	if this.loadPost(&postMd, nil) {
		return nil
	}

	var comments []*models.Comment
	this.loadComments(&postMd, &comments)

	//mark all notification as read
	if this.IsLogin {
		models.MarkNortificationAsRead(this.User.Id, postMd.Id)
	}

	//check whether this post is favorited
	isPostFav, _ := models.IsPostFavorite(postMd.Id, int64(this.User.Id))
	this.Data["IsPostFav"] = isPostFav

	form := post.CommentForm{}
	this.SetFormSets(&form)
	//increment PageViewCount

	post.PostBrowsersAdd(this.User.Id, utils.IP(this.Req()), &postMd)
	return this.Render("post/post.html", this.Data)
}
Example #2
0
func (this *SocialAuthRouter) Post() {
	this.TplNames = "auth/connect.html"

	if this.CheckLoginRedirect(false) {
		return
	}

	var socialType social.SocialType
	if !this.canConnect(&socialType) {
		this.Redirect(setting.SocialAuth.LoginURL, 302)
		return
	}

	p, ok := social.GetProviderByType(socialType)
	if !ok {
		this.Redirect(setting.SocialAuth.LoginURL, 302)
		return
	}

	var form interface{}

	formL := auth.OAuthLoginForm{}
	this.SetFormSets(&formL)

	formR := auth.OAuthRegisterForm{Locale: this.Locale}
	this.SetFormSets(&formR)

	action := this.GetString("action")
	if action == "connect" {
		form = &formL
	} else {
		form = &formR
	}

	this.Data["Action"] = action
	this.Data["Social"] = socialType

	// valid form and put errors to template context
	if this.ValidFormSets(form) == false {
		return
	}

	var user models.User

	switch action {
	case "connect":
		key := "auth.login." + formL.UserName + utils.IP(this.Req())
		if times, ok := utils.TimesReachedTest(key, setting.LoginMaxRetries); ok {
			this.Data["ErrorReached"] = true
		} else if auth.VerifyUser(&user, formL.UserName, formL.Password) {
			goto connect
		} else {
			utils.TimesReachedSet(key, times, setting.LoginFailedBlocks)
		}

	default:
		if err := auth.RegisterUser(&user, formR.UserName, formR.Email, formR.Password, this.Locale); err == nil {

			auth.SendRegisterMail(middlewares.Renders, this.Locale, &user)

			goto connect

		} else {
			log.Error("Register: Failed ", err)
		}
	}

failed:
	this.Data["Error"] = true
	return

connect:
	if loginRedirect, _, err := setting.SocialAuth.ConnectAndLogin(this.Context, &this.Session, socialType, int(user.Id)); err != nil {
		log.Error("ConnectAndLogin:"******"connect":
		this.FlashRedirect("/settings/profile", 302, "ConnectSuccess", p.GetName())
	default:
		this.FlashRedirect("/settings/profile", 302, "RegSuccess")
	}
}
Example #3
0
File: auth.go Project: zeuson/wego
// Login implemented user login.
func (this *Login) Post() {
	this.Data["IsLoginPage"] = true

	// no need login
	if this.CheckLoginRedirect(false) {
		return
	}

	var user models.User
	var key string
	ajaxErrMsg := "auth.login_error_ajax"

	form := auth.LoginForm{}
	// valid form and put errors to template context
	if this.ValidFormSets(&form) == false {
		if this.IsAjax() {
			goto ajaxError
		}
		return
	}

	key = "auth.login." + form.UserName + utils.IP(this.Req())
	if times, ok := utils.TimesReachedTest(key, setting.LoginMaxRetries); ok {
		if this.IsAjax() {
			ajaxErrMsg = "auth.login_error_times_reached"
			goto ajaxError
		}
		this.Data["ErrorReached"] = true

	} else if auth.VerifyUser(&user, form.UserName, form.Password) {
		loginRedirect := this.LoginUser(&user, form.Remember)

		if this.IsAjax() {
			this.Data["json"] = map[string]interface{}{
				"success":  true,
				"message":  this.Tr("auth.login_success_ajax"),
				"redirect": loginRedirect,
			}
			this.ServeJson(this.Data)
			return
		}

		this.Redirect(loginRedirect, 302)
		return
	} else {
		utils.TimesReachedSet(key, times, setting.LoginFailedBlocks)
		if this.IsAjax() {
			goto ajaxError
		}
	}
	this.Data["Error"] = true
	this.Render("auth/login.html", this.Data)
	return

ajaxError:
	this.Data["json"] = map[string]interface{}{
		"success": false,
		"message": this.Tr(ajaxErrMsg),
		"once":    this.Data["once_token"],
	}
	this.ServeJson(this.Data)
}