Ejemplo n.º 1
0
func login(c *api.Context, w http.ResponseWriter, r *http.Request) {
	if !CheckBrowserCompatability(c, r) {
		return
	}

	teamName := "Beta"
	teamDomain := ""
	siteDomain := "." + utils.Cfg.ServiceSettings.Domain

	if utils.Cfg.ServiceSettings.Mode == utils.MODE_DEV {
		teamDomain = "developer"
	} else if utils.Cfg.ServiceSettings.Mode == utils.MODE_BETA {
		teamDomain = "beta"
	} else {
		teamDomain, siteDomain = model.GetSubDomain(c.TeamUrl)
		siteDomain = "." + siteDomain + ".com"

		if tResult := <-api.Srv.Store.Team().GetByDomain(teamDomain); tResult.Err != nil {
			l4g.Error("Couldn't find team teamDomain=%v, siteDomain=%v, teamUrl=%v, err=%v", teamDomain, siteDomain, c.TeamUrl, tResult.Err.Message)
		} else {
			teamName = tResult.Data.(*model.Team).Name
		}
	}

	page := NewHtmlTemplatePage("login", "Login")
	page.Props["TeamName"] = teamName
	page.Props["TeamDomain"] = teamDomain
	page.Props["SiteDomain"] = siteDomain
	page.Render(c, w)
}
Ejemplo n.º 2
0
func resetPassword(c *api.Context, w http.ResponseWriter, r *http.Request) {
	isResetLink := true
	hash := r.URL.Query().Get("h")
	data := r.URL.Query().Get("d")

	if len(hash) == 0 || len(data) == 0 {
		isResetLink = false
	} else {
		if !model.ComparePassword(hash, fmt.Sprintf("%v:%v", data, utils.Cfg.ServiceSettings.ResetSalt)) {
			c.Err = model.NewAppError("resetPassword", "The reset link does not appear to be valid", "")
			return
		}

		props := model.MapFromJson(strings.NewReader(data))

		t, err := strconv.ParseInt(props["time"], 10, 64)
		if err != nil || model.GetMillis()-t > 1000*60*60 { // one hour
			c.Err = model.NewAppError("resetPassword", "The signup link has expired", "")
			return
		}
	}

	teamName := "Developer/Beta"
	domain := ""
	if utils.Cfg.ServiceSettings.Mode != utils.MODE_DEV {
		domain, _ = model.GetSubDomain(c.TeamUrl)

		var team *model.Team
		if tResult := <-api.Srv.Store.Team().GetByDomain(domain); tResult.Err != nil {
			c.Err = tResult.Err
			return
		} else {
			team = tResult.Data.(*model.Team)
		}

		if team != nil {
			teamName = team.Name
		}
	}

	page := NewHtmlTemplatePage("password_reset", "")
	page.Title = "Reset Password - " + page.SiteName
	page.Props["TeamName"] = teamName
	page.Props["Hash"] = hash
	page.Props["Data"] = data
	page.Props["Domain"] = domain
	page.Props["IsReset"] = strconv.FormatBool(isResetLink)
	page.Render(c, w)
}