func submitContact(ctx *web.Context) { capId := ctx.Params["captcha_id"] capSoln := ctx.Params["captcha_soln"] usrNameStr := ctx.Params["contact_user_name"] usrEmailStr := ctx.Params["contact_user_email"] comment := ctx.Params["contact_comment"] //Make sure the user filled out the form if usrNameStr == "" { contactPageError(ctx, capId, "Please Enter your name", comment, usrEmailStr, usrNameStr) } else if usrEmailStr == "" { contactPageError(ctx, capId, "You must provide your email address", comment, usrEmailStr, usrNameStr) return } else if comment == "" { contactPageError(ctx, capId, "You must provide a comment as to why you are contacting us", comment, usrEmailStr, usrNameStr) return } else if capSoln == "" { contactPageError(ctx, capId, "You must provide a solution to the CAPTCHA", comment, usrEmailStr, usrNameStr) return } //Verify the user's CAPTCHA solution goodCapSoln, reason, err := goodCaptchaSolution(ctx, capId, capSoln) if err != nil { internalError(ctx, err) return } else if !goodCapSoln { captchaId := captcha.NewLen(CAPTCHA_MIN_LENGTH + rand.Intn(CAPTCHA_VARIANCE+1)) contactPageError(ctx, captchaId, reason, comment, usrEmailStr, usrNameStr) return } //verify the user's email address: emailAddr, err := mail.ParseAddress(usrEmailStr) if err != nil { internalError(ctx, err) return } else if emailAddr == nil || emailAddr.Address != usrEmailStr { captchaId := captcha.NewLen(CAPTCHA_MIN_LENGTH + rand.Intn(CAPTCHA_VARIANCE+1)) contactPageError(ctx, captchaId, "The email address you provided appears to be invalid.", comment, usrEmailStr, usrNameStr) return } subject := "Contact Request to Redu.se Admins" body := "<strong>User Name:</strong> " + escapeHTML(usrNameStr) + "<br/>" body += "<strong>User Email:</strong> " + escapeHTML(emailAddr.String()) + "<br/>" body += "<strong>User Comment:</strong><div style=\"padding-left:15px;\">" + escapeHTML(comment) + "</div>" err = sendHTMLEmailToAdmins(subject, body) if err != nil { internalError(ctx, err) return } commonTemplate(ctx, "generic.html", map[string]string{"title_text": "Thank You", "body_text": "Your contact request was submitted"}) }
func main() { martini.Env = martini.Prod m := martini.Classic() m.Use(martini.Static("../../admin/static/")) m.Use(martini.Static(APP_STORE_DIR)) m.Use(sessions.Sessions("compass_session", sessions.NewCookieStore([]byte("compass_session_cookie")))) m.Get("/", func(w http.ResponseWriter) string { w.Header().Set("content-type", "text/html") return SCRIPT_LOGIN }) m.Get("/checkcode", func(r *http.Request, w http.ResponseWriter, s sessions.Session) { code := captcha.NewLen(4) s.Set("checkcode", code) captcha.WriteImage(w, code, 110, 40) }) showTemplate([]string{"footer", "form", "index", "left", "login", "main", "right", "top"}, m) for actionName, actionHandler := range admin.ActionHandlers { m.Post(fmt.Sprintf("/action/%s", actionName), actionHandler) } m.RunOnAddr(SERVER_ADDR) }
/* 刷新验证码 */ func (this *CheckController) FreshCap() { this.Data["json"] = map[string]interface{}{ "ok": true, "data": captcha.NewLen(6), } this.ServeJson() }
/* Serve the homepage Parameters: ctx: the context of the http request */ func home(ctx *web.Context) { // CAPTCHA length will be in [CAPTCHA_MIN_LENGTH, CAPTCHA_MIN_LENGTH + CAPTCHA_VARIANCE] captchaId := captcha.NewLen(CAPTCHA_MIN_LENGTH + rand.Intn(CAPTCHA_VARIANCE+1)) commonTemplate(ctx, "home.html", map[string]string{"captcha_id": captchaId, "user_url": ctx.Params["url"], "captcha_soln_min_length": strconv.Itoa(CAPTCHA_MIN_LENGTH), "captcha_soln_max_length": strconv.Itoa(CAPTCHA_MIN_LENGTH + CAPTCHA_VARIANCE), }) }
// 用户注册 // uri: /account/register{json:(|.json)} func RegisterHandler(rw http.ResponseWriter, req *http.Request) { if _, ok := filter.CurrentUser(req); ok { util.Redirect(rw, req, "/") return } vars := mux.Vars(req) username := req.PostFormValue("username") // 请求注册页面 if username == "" || req.Method != "POST" || vars["json"] == "" { filter.SetData(req, map[string]interface{}{"captchaId": captcha.NewLen(4)}) req.Form.Set(filter.CONTENT_TPL_KEY, "/template/register.html") return } // 校验验证码 if !captcha.VerifyString(req.PostFormValue("captchaid"), req.PostFormValue("captchaSolution")) { fmt.Fprint(rw, `{"ok": 0, "error":"验证码错误"}`) return } // 入库 errMsg, err := service.CreateUser(req.PostForm) if err != nil { // bugfix:http://studygolang.com/topics/255 if errMsg == "" { errMsg = err.Error() } fmt.Fprint(rw, `{"ok": 0, "error":"`, errMsg, `"}`) return } // 注册成功,自动为其登录 setCookie(rw, req, req.PostFormValue("username")) // 发送欢迎邮件 go sendWelcomeMail([]string{req.PostFormValue("email")}) fmt.Fprint(rw, `{"ok": 1, "msg":"注册成功"}`) }
func (self AccountController) Register(ctx echo.Context) error { if _, ok := ctx.Get("user").(*model.Me); ok { return ctx.Redirect(http.StatusSeeOther, "/") } registerTpl := "register.html" username := ctx.FormValue("username") // 请求注册页面 if username == "" || ctx.Request().Method() != "POST" { return render(ctx, registerTpl, map[string]interface{}{"captchaId": captcha.NewLen(4)}) } data := map[string]interface{}{ "username": username, "email": ctx.FormValue("email"), "captchaId": captcha.NewLen(4), } // 校验验证码 if !captcha.VerifyString(ctx.FormValue("captchaid"), ctx.FormValue("captchaSolution")) { data["error"] = "验证码错误" return render(ctx, registerTpl, data) } if ctx.FormValue("passwd") != ctx.FormValue("pass2") { data["error"] = "两次密码不一致" return render(ctx, registerTpl, data) } fields := []string{"username", "email", "passwd"} form := url.Values{} for _, field := range fields { form.Set(field, ctx.FormValue(field)) } // 入库 errMsg, err := logic.DefaultUser.CreateUser(ctx, form) if err != nil { // bugfix:http://studygolang.com/topics/255 if errMsg == "" { errMsg = err.Error() } data["error"] = errMsg return render(ctx, registerTpl, data) } email := ctx.FormValue("email") uuid := self.genUUID(email) var emailUrl string if strings.HasSuffix(email, "@gmail.com") { emailUrl = "http://mail.google.com" } else { pos := strings.LastIndex(email, "@") emailUrl = "http://mail." + email[pos+1:] } data = map[string]interface{}{ "success": template.HTML(` <div style="padding:30px 30px 50px 30px;"> <div style="color:#339502;font-size:22px;line-height: 2.5;">恭喜您注册成功!</div> 我们已经发送一封邮件到 ` + email + `,请您根据提示信息完成邮箱验证.<br><br> <a href="` + emailUrl + `" target="_blank"><button type="button" class="btn btn-success">立即验证</button></a> <button type="button" class="btn btn-link" data-uuid="` + uuid + `" id="resend_email">未收到?再发一次</button> </div>`), } // 需要检验邮箱的正确性 go logic.DefaultEmail.SendActivateMail(email, uuid) return render(ctx, registerTpl, data) }
//获取验证码 func (c *Ajax) GetCaptcha() revel.Result { CaptchaId := captcha.NewLen(6) return c.RenderText(CaptchaId) }
//登陆 func (c *User) Login(admin *models.Admin) revel.Result { if c.Request.Method == "GET" { title := "登陆--GoCMS管理系统" CaptchaId := captcha.NewLen(6) return c.Render(title, CaptchaId) } else { var username string = c.Params.Get("username") var password string = c.Params.Get("password") var captchaId string = c.Params.Get("captchaId") var verify string = c.Params.Get("verify") data := make(map[string]string) if !captcha.VerifyString(captchaId, verify) { data["status"] = "0" data["url"] = "/" data["message"] = "验证码错误!" return c.RenderJson(data) } if len(username) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = "请填写用户名!" return c.RenderJson(data) } if len(password) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = "请填写密码!" return c.RenderJson(data) } if len(verify) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = "请填写验证码!" return c.RenderJson(data) } admin_info := admin.GetByName(username) if admin_info.Id <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = "用户名错误!" } else if admin_info.Status == 0 && admin_info.Id != 1 { data["status"] = "0" data["url"] = "/" data["message"] = "此账号禁止登陆!" } else if admin_info.Role.Status == 0 && admin_info.Id != 1 { data["status"] = "0" data["url"] = "/" data["message"] = "所属角色禁止登陆!" } else if username == admin_info.Username && utils.Md5(password) == admin_info.Password { c.Session["UserID"] = fmt.Sprintf("%d", admin_info.Id) c.Flash.Success("登陆成功!欢迎您 " + admin_info.Realname) c.Flash.Out["url"] = "/" //更新登陆时间 admin.UpdateLoginTime(admin_info.Id) //****************************************** //管理员日志 logs := new(models.Logs) desc := "登陆用户名:" + admin_info.Username + "|^|登陆系统!|^|登陆ID:" + fmt.Sprintf("%d", admin_info.Id) logs.Save(admin_info, c.Controller, desc) //***************************************** data["status"] = "1" data["url"] = "/Message/" data["message"] = "登陆成功!" } else { data["status"] = "0" data["url"] = "/" data["message"] = "密码错误!" } return c.RenderJson(data) } }
// 获取验证代码 func (this *Captcha) Code() string { return captcha.NewLen(6) }
//登陆 func (c *User) Login(admin *models.Admin) revel.Result { if c.Request.Method == "GET" { title := "登陆--GoCMS管理系统" CaptchaId := captcha.NewLen(6) return c.Render(title, CaptchaId) } else { var username string = c.Params.Get("username") var password string = c.Params.Get("password") var captchaId string = c.Params.Get("captchaId") var verify string = c.Params.Get("verify") data := make(map[string]string) if LANG, ok := c.Session["Lang"]; ok { //设置语言 c.Request.Locale = LANG } else { //设置默认语言 c.Request.Locale = "zh" } if !captcha.VerifyString(captchaId, verify) { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("verification_code") return c.RenderJson(data) } if len(username) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_user_name") return c.RenderJson(data) } if len(password) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_password") return c.RenderJson(data) } if len(verify) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_verification_code") return c.RenderJson(data) } admin_info := admin.GetByName(username) if admin_info.Id <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("admin_username_error") } else if admin_info.Status == 0 && admin_info.Id != 1 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("admin_forbid_login") } else if admin_info.Role.Status == 0 && admin_info.Id != 1 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("admin_forbid_role_login") } else if username == admin_info.Username && utils.Md5(password) == admin_info.Password { /* * %% 印出百分比符号,不转换。 * %c 整数转成对应的 ASCII 字元。 * %d 整数转成十进位。 * %f 倍精确度数字转成浮点数。 * %o 整数转成八进位。 * %s 整数转成字符串。 * %x 整数转成小写十六进位。 * %X 整数转成大写十六进位 */ c.Session["UserID"] = fmt.Sprintf("%d", admin_info.Id) c.Session["Lang"] = admin_info.Lang c.Flash.Success(c.Message("login_success")) c.Flash.Out["url"] = "/" //更新登陆时间 if ip := c.Request.Header.Get("X-Forwarded-For"); ip != "" { ips := strings.Split(ip, ",") if len(ips) > 0 && ips[0] != "" { rip := strings.Split(ips[0], ":") admin.Lastloginip = rip[0] } } else { ip := strings.Split(c.Request.RemoteAddr, ":") if len(ip) > 0 { if ip[0] != "[" { admin.Lastloginip = ip[0] } } } admin.UpdateLoginTime(admin_info.Id) //****************************************** //管理员日志 logs := new(models.Logs) desc := "登陆用户名:" + admin_info.Username + "|^|登陆系统!|^|登陆ID:" + fmt.Sprintf("%d", admin_info.Id) logs.Save(admin_info, c.Controller, desc) //***************************************** data["status"] = "1" data["url"] = "/Message/" data["message"] = c.Message("login_success") } else { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_password_error") } return c.RenderJson(data) } }
/* recieves a link report submission, verifies the CAPTCHA, makes a report struct, and attempts to add it to the database */ func submitReport(ctx *web.Context) { capId := ctx.Params["captcha_id"] capSoln := ctx.Params["captcha_soln"] linkId := ctx.Params["linkId"] reportTypeString := ctx.Params["reportReason"] comment := ctx.Params["report_comment"] //Make sure the user filled out the form if linkId == "" { submitReportUserError(ctx, capId, linkId, comment, "You must provide a link to report") return } else if reportTypeString == "" { submitReportUserError(ctx, capId, linkId, comment, "You must select a reason that you are reporting this link") return } else if comment == "" { submitReportUserError(ctx, capId, linkId, comment, "You must provide a comment as to why you are reporting this link") return } else if capSoln == "" { submitReportUserError(ctx, capId, linkId, comment, "You must provide a solution to the CAPTCHA") return } //Verify the user's CAPTCHA solution goodCapSoln, reason, err := goodCaptchaSolution(ctx, capId, capSoln) if err != nil { internalError(ctx, err) return } else if !goodCapSoln { captchaId := captcha.NewLen(CAPTCHA_MIN_LENGTH + rand.Intn(CAPTCHA_VARIANCE+1)) submitReportUserError(ctx, captchaId, linkId, comment, reason) return } //make the hash all uppercase upperHash := strings.ToUpper(linkId) // attempt to parse the IP address of the user that made this report var rawIP string if herokuProduction { // because of Heroku's reverse router system, we need to grab the user's IP from the X-Forwarded-For header forwardSlice := ctx.Request.Header["X-Forwarded-For"] //The client's IP is guaranteed to be the last element rawIP = forwardSlice[len(forwardSlice)-1] } else { //otherwise we can just grab the IP from the request rawIP = string(ctx.Request.RemoteAddr) } //trim the IP address of any extra stuff (whitespace, portnumber, etc.) trimmedIP, err := trimIPAddress(rawIP) if err != nil { internalError(ctx, err) return } //attempt to parse the IP ip := net.ParseIP(trimmedIP) if ip == nil { internalError(ctx, errors.New("Unable to parse client IP address")) return } ipStr := ip.String() //Generate a new report struct to add to the database rep := NewReport(upperHash, ipStr, ReportTypeForString(reportTypeString), comment) //attempt to add the report to the database numReports, exists, err := db_addReport(rep) if _, isREE := err.(ReportExistsError); isREE { //A report for this link already exists from the user's IP address commonTemplate(ctx, "generic.html", map[string]string{"title_text": "Report Exists", "body_text": "A report for that link already exists from your IP address.", }) } else if err != nil { //any other errors internalError(ctx, err) } else if !exists { //The link doens't exist bStr := "The link redu.se/" + linkId + " does not exist." captchaId := captcha.NewLen(CAPTCHA_MIN_LENGTH + rand.Intn(CAPTCHA_VARIANCE+1)) submitReportUserError(ctx, captchaId, linkId, comment, bStr) return } //If the number of reports has increased over the flag point, send an email to the admins if numReports >= NUM_REPORTS_TO_FLAG { emailBody := "The following link has been reported by users:<br/>" emailBody += "<strong>LinkID:</strong> " + escapeHTML(linkId) + "<br/>" target, _, _, err := db_linkForHash(upperHash) if err != nil { internalError(ctx, err) return } emailBody += "<strong>Target URL:</strong> <a href=\"" + target + "\">" + escapeHTML(target) + "</a><br/><br/>" reports, err := db_reportsForHash(upperHash) if err != nil { internalError(ctx, err) return } for i, v := range reports { emailBody += fmt.Sprintf("Report %v of %v:<br/>", i+1, len(reports)) emailBody += "<div style=\"padding-lefT:15px;\">" + escapeHTML(v.String()) + "</div><br/>" } err = sendHTMLEmailToAdmins("Link Reported", emailBody) if err != nil { internalError(ctx, err) return } } //Tell the user that their report has been recieved commonTemplate(ctx, "generic.html", map[string]string{"title_text": "Thank You", "body_text": "Your report was submitted"}) }
/* Generates a link for the URL the user entered and serves a page with the link, in the following order - Checks that the user entered a correct solution to the CAPTCHA - Checks that the user entered a valid URL - Generates a full hash string of the URL, and attempts to find an unused short-hash: - If the short-hash is used for a different URL, add on the next character from the full hash & check again - If the short-hash is used for the same URL, serve the user a page with the link - If the short-hash is unused, attempt to add it to the database, and then serve the user a page with the link */ func generate(ctx *web.Context) { urlStr := ctx.Params["url"] //Verify the user's CAPTCHA solution capId := ctx.Params["captcha_id"] capSoln := ctx.Params["captcha_soln"] goodCapSoln, reason, err := goodCaptchaSolution(ctx, capId, capSoln) if err != nil { internalError(ctx, err) return } else if !goodCapSoln { captchaId := captcha.NewLen(CAPTCHA_MIN_LENGTH + rand.Intn(CAPTCHA_VARIANCE+1)) commonTemplate(ctx, "home.html", map[string]string{"title_text": "", "captcha_id": captchaId, "captcha_soln_min_length": strconv.Itoa(CAPTCHA_MIN_LENGTH), "captcha_soln_max_length": strconv.Itoa(CAPTCHA_MIN_LENGTH + CAPTCHA_VARIANCE), "error_msg": reason, "user_url": urlStr, }) return } //Check to make sure we were given a valid URL validURL, isValid, err := validateURL(urlStr) if err != nil { internalError(ctx, errors.New("Error validating URL: "+err.Error())) return } else if !isValid { invalidURLPage(ctx, validURL) return } urlStr = validURL //TODO: Check the domain against a blacklist // blacklisted, err := isBlacklisted(urlStr) // if err != nil { // internalError(ctx, errors.New("Could not check URL against blacklist. ~ " + err.Error())) // return // } else if blacklisted { // blacklistedPage(ctx, urlStr) // return // } //Generate a new MD5 hasher, and hash the urlStr hasher := md5.New() io.WriteString(hasher, urlStr) hashBytes := hasher.Sum(nil) hashStr := base32.StdEncoding.EncodeToString(hashBytes) //Check for collisions (ie. different links resulting in the same short-hash), and fix them //(by adding the next character from the full hash to the short hash, and checking for another collision) var testHash string var collision bool = true var alreadyExists = false for i := LINK_START_LENGTH; i <= len(hashStr) && collision; i++ { testHash = hashStr[:i] //Check if this shorthash already exists in the database val, _, exists, err := db_linkForHash(testHash) if err != nil { internalError(ctx, errors.New("Database Error: "+err.Error())) return } if !exists { //No link exists for this short hash, so there is no collision collision = false } else if val == urlStr { //This short has is used already, but for the same URL collision = false alreadyExists = true } //otherwise, there was a collision, so check the short-hash of one char longer } //if we have hit the maximum length of the hash, and there is still a collision, throw an error if collision { internalError(ctx, errors.New("Could not resolve collision. Hash: "+hashStr+" Link: "+urlStr)) return } finalHash := testHash //if the link did not already exist (Optimization: db_addLink checks this too, but we've already done it here, so why do it again?) if !alreadyExists { //Save the link to the link table err := db_addLink(finalHash, urlStr) if err != nil { internalError(ctx, errors.New("Database Error: could not add link to database. \""+err.Error()+"\"")) return } } commonTemplate(ctx, "generate.html", map[string]string{"title_text": "Generated Link", "dest_url": urlStr, "link_hash": strings.ToLower(finalHash), }) }
func (c *Cosgo) homeHandler(w http.ResponseWriter, r *http.Request) { hitcounter = hitcounter + 1 c.Visitors = hitcounter if !*quiet { log.Printf("Visitor #%v: %s %s %s %s", c.Visitors, r.UserAgent(), r.RemoteAddr, r.Host, r.RequestURI) } query, err := url.ParseQuery(r.URL.RawQuery) if err != nil { fmt.Println(err) return } var status, reason string if query.Get("status") != "" { if query["status"][0] == "1" { status = "Thanks! Your message was sent." } } // Send an error message without using session if query.Get("r") != "" { if query["status"][0] == "0" { switch query["r"][0] { default: reason = "Error." case "1": reason = "Bad method." case "2": reason = "Bad endpoint." case "3": reason = "Bad capcha." case "4": reason = "Bad email address." case "5": reason = "Bad message." case "6": reason = "Bad error!" } status = "Your message was not sent: " + reason } } thyme := time.Now() nowtime := thyme.Format("Mon Jan 2 15:04:05 2006") uptime := time.Since(timeboot).String() fortune := newfortune() t, templateerr := template.New("Index").Funcs(funcMap).ParseFiles(c.templatesDir + "index.html") if templateerr != nil { // Something happened to the template since booting successfully. Must be 100% correct HTML syntax. log.Println("Almost fatal") log.Println(templateerr) fmt.Fprintf(w, "We are experiencing some technical difficulties. Please come back soon!") } else { // get current URLKey to insert into template c.rw.RLock() postkey := c.URLKey c.rw.RUnlock() data := map[string]interface{}{ "Now": nowtime, // Now "Status": status, // notify of form success or fail "Version": version, // Cosgo version "Hits": hitcounter, // Visitor hits "Uptime": uptime, // Uptime "Boottime": timeboot, // Boot time "Fortune": fortune, // random fortune from fortunes.txt "Title": c.Name, // Site Name from config "PublicKey": string(c.publicKey), // GPG key "Key": postkey, // POST URL key csrf.TemplateTag: csrf.TemplateField(r), "CaptchaId": captcha.NewLen(CaptchaLength + rand.Intn(CaptchaVariation)), } t.ExecuteTemplate(w, "Index", data) } }
//登陆 func (c *User) Login(admin *models.Admin) revel.Result { if c.Request.Method == "GET" { title := "登陆--GoCMS管理系统" CaptchaId := captcha.NewLen(6) return c.Render(title, CaptchaId) } else { var username string = c.Params.Get("username") var password string = c.Params.Get("password") var captchaId string = c.Params.Get("captchaId") var verify string = c.Params.Get("verify") data := make(map[string]string) if LANG, ok := c.Session["Lang"]; ok { //设置语言 c.Request.Locale = LANG } else { //设置默认语言 c.Request.Locale = "zh" } if !captcha.VerifyString(captchaId, verify) { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("verification_code") return c.RenderJson(data) } if len(username) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_user_name") return c.RenderJson(data) } if len(password) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_password") return c.RenderJson(data) } if len(verify) <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_verification_code") return c.RenderJson(data) } admin_info := admin.GetByName(username) if admin_info.Id <= 0 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("admin_username_error") } else if admin_info.Status == 0 && admin_info.Id != 1 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("admin_forbid_login") } else if admin_info.Role.Status == 0 && admin_info.Id != 1 { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("admin_forbid_role_login") } else if username == admin_info.Username && utils.Md5(password) == admin_info.Password { c.Session["UserID"] = fmt.Sprintf("%d", admin_info.Id) c.Session["Lang"] = admin_info.Lang c.Flash.Success(c.Message("login_success")) c.Flash.Out["url"] = "/" //更新登陆时间 admin.UpdateLoginTime(admin_info.Id) //****************************************** //管理员日志 logs := new(models.Logs) desc := "登陆用户名:" + admin_info.Username + "|^|登陆系统!|^|登陆ID:" + fmt.Sprintf("%d", admin_info.Id) logs.Save(admin_info, c.Controller, desc) //***************************************** data["status"] = "1" data["url"] = "/Message/" data["message"] = c.Message("login_success") } else { data["status"] = "0" data["url"] = "/" data["message"] = c.Message("login_password_error") } return c.RenderJson(data) } }
//首页 func (c *Captcha) Index() revel.Result { captcha.Server(250, 62) CaptchaId := captcha.NewLen(6) captcha.WriteImage(c.Response.Out, CaptchaId, 250, 62) return nil }