public.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package admin
  2. import (
  3. "gfast/app/service/user"
  4. "gfast/library/response"
  5. "github.com/gogf/gf/net/ghttp"
  6. "github.com/gogf/gf/util/gvalid"
  7. "github.com/mojocn/base64Captcha"
  8. )
  9. type Public struct{}
  10. //Login 用户登陆验证
  11. func (p *Public) Login(r *ghttp.Request) {
  12. data := r.GetPostMapStrStr()
  13. rules := map[string]string{
  14. "passport": "required",
  15. "password": "required",
  16. }
  17. msgs := map[string]interface{}{
  18. "passport": "账号不能为空",
  19. "password": "密码不能为空",
  20. }
  21. if e := gvalid.CheckMap(data, rules, msgs); e != nil {
  22. response.Json(r, 1, e.String())
  23. }
  24. if err := user.SignIn(data["passport"], data["password"], r.Session); err != nil {
  25. response.Json(r, 1, err.Error())
  26. } else {
  27. response.Json(r, 0, "ok")
  28. }
  29. }
  30. func (p *Public) Verify(r *ghttp.Request) {
  31. //字符,公式,验证码配置
  32. var configC = base64Captcha.ConfigCharacter{
  33. Height: 60,
  34. Width: 240,
  35. //const CaptchaModeNumber:数字,CaptchaModeAlphabet:字母,CaptchaModeArithmetic:算术,CaptchaModeNumberAlphabet:数字字母混合.
  36. Mode: base64Captcha.CaptchaModeNumberAlphabet,
  37. ComplexOfNoiseText: base64Captcha.CaptchaComplexLower,
  38. ComplexOfNoiseDot: base64Captcha.CaptchaComplexLower,
  39. IsShowHollowLine: false,
  40. IsShowNoiseDot: false,
  41. IsShowNoiseText: false,
  42. IsShowSlimeLine: false,
  43. IsShowSineLine: true,
  44. CaptchaLen: 4,
  45. }
  46. //创建字符公式验证码.
  47. //GenerateCaptcha 第一个参数为空字符串,包会自动在服务器一个随机种子给你产生随机uiid.
  48. idKeyC, capC := base64Captcha.GenerateCaptcha("8nM77YhE2xOvU6GMQ33A", configC)
  49. //以base64编码
  50. base64stringC := base64Captcha.CaptchaWriteToBase64Encoding(capC)
  51. r.Response.Header().Set("Content-type", "text/html")
  52. r.Response.Write(idKeyC, "\n", "<img src=\""+base64stringC+"\">")
  53. }
  54. func (p *Public) CheckVerify(r *ghttp.Request) {
  55. data := r.GetQueryMapStrStr()
  56. if base64Captcha.VerifyCaptchaAndIsClear(data["key"], data["value"], false) {
  57. r.Response.Write("验证成功")
  58. } else {
  59. r.Response.Write("验证失败")
  60. }
  61. }