Merge branch 'main' into ai_fix_something

This commit is contained in:
aichy126 2022-10-24 12:08:04 +08:00
commit d5c344f77f
7 changed files with 64 additions and 35 deletions

View File

@ -1,5 +1,5 @@
<a href="https://answer.dev">
<img alt="logo" src="docs/img/answer-logo-flat.svg" height="63px">
<img alt="logo" src="docs/img/logo.svg" height="99px">
</a>
# Answer - Build Q&A community

View File

@ -1,5 +1,5 @@
<a href="https://answer.dev">
<img alt="logo" src="docs/img/answer-logo-flat.svg" height="63px">
<img alt="logo" src="docs/img/logo.svg" height="99px">
</a>
# Answer - 构建问答社区

View File

@ -1,9 +0,0 @@
<svg width="110" height="28" viewBox="0 0 110 28" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M0 6.4C0 4.15979 0 3.03969 0.435974 2.18404C0.819467 1.43139 1.43139 0.819467 2.18404 0.435974C3.03969 0 4.15979 0 6.4 0H21.6C23.8402 0 24.9603 0 25.816 0.435974C26.5686 0.819467 27.1805 1.43139 27.564 2.18404C28 3.03969 28 4.15979 28 6.4V16.0892C28 18.9608 28 20.3967 27.5628 21.6643C27.1761 22.7853 26.5451 23.8063 25.7153 24.6535C24.7771 25.6115 23.4928 26.2536 20.9244 27.5378L20.9243 27.5378L20 28V24H6.4C4.15979 24 3.03969 24 2.18404 23.564C1.43139 23.1805 0.819467 22.5686 0.435974 21.816C0 20.9603 0 19.8402 0 17.6V6.4ZM20 12C20 15.3137 17.3137 18 14 18C10.6954 18 8.0148 15.3285 8.00006 12.0274V12H20Z" fill="#0033FF"/>
<path d="M35.98 21.5L41.52 7.5H44.4L49.9 21.5H46.46L43.82 14.4C43.7133 14.12 43.6066 13.82 43.5 13.5C43.3933 13.18 43.2866 12.8533 43.18 12.52C43.0733 12.1733 42.9666 11.84 42.86 11.52C42.7666 11.1867 42.6866 10.88 42.62 10.6L43.22 10.58C43.14 10.9133 43.0466 11.24 42.94 11.56C42.8466 11.88 42.7466 12.2 42.64 12.52C42.5466 12.8267 42.44 13.14 42.32 13.46C42.2 13.7667 42.0866 14.0867 41.98 14.42L39.34 21.5H35.98ZM38.62 18.82L39.68 16.26H46.12L47.16 18.82H38.62Z" fill="#212529"/>
<path d="M51.3067 21.5V10.88H54.3467L54.4467 13.04L53.8067 13.28C53.9534 12.8 54.2134 12.3667 54.5867 11.98C54.9734 11.58 55.4334 11.26 55.9667 11.02C56.5 10.78 57.06 10.66 57.6467 10.66C58.4467 10.66 59.12 10.8267 59.6667 11.16C60.2134 11.48 60.6267 11.9667 60.9067 12.62C61.1867 13.26 61.3267 14.0467 61.3267 14.98V21.5H58.1067V15.24C58.1067 14.8133 58.0467 14.46 57.9267 14.18C57.8067 13.9 57.62 13.6933 57.3667 13.56C57.1267 13.4133 56.8267 13.3467 56.4667 13.36C56.1867 13.36 55.9267 13.4067 55.6867 13.5C55.4467 13.58 55.24 13.7067 55.0667 13.88C54.8934 14.04 54.7534 14.2267 54.6467 14.44C54.5534 14.6533 54.5067 14.8867 54.5067 15.14V21.5H52.9267C52.5534 21.5 52.2334 21.5 51.9667 21.5C51.7 21.5 51.48 21.5 51.3067 21.5Z" fill="#212529"/>
<path d="M67.582 21.7C66.542 21.7 65.622 21.5333 64.822 21.2C64.0353 20.8667 63.4087 20.42 62.942 19.86L64.882 18.18C65.2953 18.5933 65.762 18.9 66.282 19.1C66.802 19.2867 67.2953 19.38 67.762 19.38C67.9487 19.38 68.1153 19.36 68.262 19.32C68.4087 19.28 68.5287 19.2267 68.622 19.16C68.7287 19.08 68.8087 18.9933 68.862 18.9C68.9153 18.7933 68.942 18.6733 68.942 18.54C68.942 18.2733 68.822 18.0667 68.582 17.92C68.462 17.8533 68.262 17.7733 67.982 17.68C67.702 17.5867 67.342 17.48 66.902 17.36C66.2753 17.2 65.7287 17.0133 65.262 16.8C64.8087 16.5733 64.4353 16.3133 64.142 16.02C63.8753 15.74 63.6687 15.4333 63.522 15.1C63.3753 14.7533 63.302 14.3667 63.302 13.94C63.302 13.4467 63.4153 13 63.642 12.6C63.882 12.2 64.1953 11.8533 64.582 11.56C64.982 11.2667 65.4353 11.0467 65.942 10.9C66.462 10.74 66.9953 10.66 67.542 10.66C68.1287 10.66 68.6887 10.7267 69.222 10.86C69.7553 10.9933 70.2487 11.18 70.702 11.42C71.1687 11.66 71.582 11.9467 71.942 12.28L70.262 14.16C70.022 13.9333 69.7487 13.7333 69.442 13.56C69.1487 13.3733 68.842 13.2267 68.522 13.12C68.202 13.0133 67.9087 12.96 67.642 12.96C67.442 12.96 67.262 12.98 67.102 13.02C66.9553 13.0467 66.8287 13.1 66.722 13.18C66.6153 13.2467 66.5353 13.3333 66.482 13.44C66.4287 13.5333 66.402 13.6467 66.402 13.78C66.402 13.9133 66.4353 14.04 66.502 14.16C66.582 14.28 66.6887 14.38 66.822 14.46C66.9553 14.54 67.1687 14.6333 67.462 14.74C67.7553 14.8333 68.1553 14.9533 68.662 15.1C69.2887 15.2733 69.8287 15.4667 70.282 15.68C70.7353 15.8933 71.0953 16.1467 71.362 16.44C71.5753 16.6667 71.7353 16.9333 71.842 17.24C71.9487 17.5333 72.002 17.8533 72.002 18.2C72.002 18.88 71.8087 19.4867 71.422 20.02C71.0487 20.54 70.5287 20.9533 69.862 21.26C69.1953 21.5533 68.4353 21.7 67.582 21.7Z" fill="#212529"/>
<path d="M76.2244 21.5L72.7244 10.88H76.1044L78.0644 17.78L77.6444 17.7L79.8444 12.34H81.7244L84.0444 17.72L83.5844 17.76L85.5444 10.88H88.9244L85.3044 21.5H82.9444L80.6444 15.8L80.8844 15.84L78.5844 21.5H76.2244Z" fill="#212529"/>
<path d="M95.3511 21.7C94.1777 21.7 93.1577 21.4667 92.2911 21C91.4244 20.52 90.7511 19.8733 90.2711 19.06C89.7911 18.2333 89.5511 17.2933 89.5511 16.24C89.5511 15.4267 89.6844 14.68 89.9511 14C90.2177 13.32 90.5911 12.7333 91.0711 12.24C91.5511 11.7333 92.1177 11.3467 92.7711 11.08C93.4377 10.8 94.1644 10.66 94.9511 10.66C95.6977 10.66 96.3777 10.7933 96.9911 11.06C97.6177 11.3267 98.1577 11.7 98.6111 12.18C99.0644 12.66 99.4111 13.2267 99.6511 13.88C99.8911 14.5333 99.9977 15.2467 99.9711 16.02L99.9511 16.88H91.4911L91.0311 15.08H97.3511L97.0111 15.46V15.06C96.9844 14.7267 96.8777 14.4333 96.6911 14.18C96.5177 13.9133 96.2844 13.7067 95.9911 13.56C95.6977 13.4133 95.3644 13.34 94.9911 13.34C94.4711 13.34 94.0244 13.4467 93.6511 13.66C93.2911 13.86 93.0177 14.16 92.8311 14.56C92.6444 14.9467 92.5511 15.4267 92.5511 16C92.5511 16.5867 92.6711 17.1 92.9111 17.54C93.1644 17.9667 93.5244 18.3 93.9911 18.54C94.4711 18.78 95.0377 18.9 95.6911 18.9C96.1444 18.9 96.5444 18.8333 96.8911 18.7C97.2511 18.5667 97.6377 18.34 98.0511 18.02L99.5511 20.14C99.1377 20.5 98.6977 20.7933 98.2311 21.02C97.7644 21.2467 97.2844 21.4133 96.7911 21.52C96.3111 21.64 95.8311 21.7 95.3511 21.7Z" fill="#212529"/>
<path d="M102.01 21.5V10.88H105.05L105.19 14.34L104.59 13.68C104.75 13.1067 105.01 12.5933 105.37 12.14C105.743 11.6867 106.176 11.3267 106.67 11.06C107.163 10.7933 107.69 10.66 108.25 10.66C108.49 10.66 108.71 10.68 108.91 10.72C109.123 10.76 109.316 10.8067 109.49 10.86L108.61 14.4C108.463 14.3067 108.263 14.2333 108.01 14.18C107.77 14.1133 107.516 14.08 107.25 14.08C106.956 14.08 106.683 14.1333 106.43 14.24C106.176 14.3333 105.963 14.4733 105.79 14.66C105.616 14.8467 105.476 15.0667 105.37 15.32C105.276 15.5733 105.23 15.86 105.23 16.18V21.5H102.01Z" fill="#212529"/>
</svg>

Before

Width:  |  Height:  |  Size: 5.7 KiB

10
docs/img/logo.svg Normal file
View File

@ -0,0 +1,10 @@
<svg width="126" height="44" viewBox="0 0 126 44" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="125.49" height="44" rx="6" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8 14.4C8 12.1598 8 11.0397 8.43597 10.184C8.81947 9.43139 9.43139 8.81947 10.184 8.43597C11.0397 8 12.1598 8 14.4 8H29.6C31.8402 8 32.9603 8 33.816 8.43597C34.5686 8.81947 35.1805 9.43139 35.564 10.184C36 11.0397 36 12.1598 36 14.4V24.0892C36 26.9608 36 28.3967 35.5628 29.6643C35.1761 30.7853 34.5451 31.8063 33.7153 32.6535C32.7771 33.6115 31.4928 34.2536 28.9244 35.5378L28 36V32H14.4C12.1598 32 11.0397 32 10.184 31.564C9.43139 31.1805 8.81947 30.5686 8.43597 29.816C8 28.9603 8 27.8402 8 25.6V14.4ZM28 20C28 23.3137 25.3137 26 22 26C18.6954 26 16.0148 23.3285 16.0001 20.0274V20H28Z" fill="#0033FF"/>
<path d="M43.98 29.5L49.52 15.5H52.4L57.9 29.5H54.46L51.82 22.4C51.7133 22.12 51.6066 21.82 51.5 21.5C51.3933 21.18 51.2866 20.8533 51.18 20.52C51.0733 20.1733 50.9666 19.84 50.86 19.52C50.7666 19.1867 50.6866 18.88 50.62 18.6L51.22 18.58C51.14 18.9133 51.0466 19.24 50.94 19.56C50.8466 19.88 50.7466 20.2 50.64 20.52C50.5466 20.8267 50.44 21.14 50.32 21.46C50.2 21.7667 50.0866 22.0867 49.98 22.42L47.34 29.5H43.98ZM46.62 26.82L47.68 24.26H54.12L55.16 26.82H46.62Z" fill="#212529"/>
<path d="M59.3067 29.5V18.88H62.3467L62.4467 21.04L61.8067 21.28C61.9534 20.8 62.2134 20.3667 62.5867 19.98C62.9734 19.58 63.4334 19.26 63.9667 19.02C64.5 18.78 65.06 18.66 65.6467 18.66C66.4467 18.66 67.12 18.8267 67.6667 19.16C68.2134 19.48 68.6267 19.9667 68.9067 20.62C69.1867 21.26 69.3267 22.0467 69.3267 22.98V29.5H66.1067V23.24C66.1067 22.8133 66.0467 22.46 65.9267 22.18C65.8067 21.9 65.62 21.6933 65.3667 21.56C65.1267 21.4133 64.8267 21.3467 64.4667 21.36C64.1867 21.36 63.9267 21.4067 63.6867 21.5C63.4467 21.58 63.24 21.7067 63.0667 21.88C62.8934 22.04 62.7534 22.2267 62.6467 22.44C62.5534 22.6533 62.5067 22.8867 62.5067 23.14V29.5H60.9267C60.5534 29.5 60.2334 29.5 59.9667 29.5C59.7 29.5 59.48 29.5 59.3067 29.5Z" fill="#212529"/>
<path d="M75.582 29.7C74.542 29.7 73.622 29.5333 72.822 29.2C72.0353 28.8667 71.4087 28.42 70.942 27.86L72.882 26.18C73.2953 26.5933 73.762 26.9 74.282 27.1C74.802 27.2867 75.2953 27.38 75.762 27.38C75.9487 27.38 76.1153 27.36 76.262 27.32C76.4087 27.28 76.5287 27.2267 76.622 27.16C76.7287 27.08 76.8087 26.9933 76.862 26.9C76.9153 26.7933 76.942 26.6733 76.942 26.54C76.942 26.2733 76.822 26.0667 76.582 25.92C76.462 25.8533 76.262 25.7733 75.982 25.68C75.702 25.5867 75.342 25.48 74.902 25.36C74.2753 25.2 73.7287 25.0133 73.262 24.8C72.8087 24.5733 72.4353 24.3133 72.142 24.02C71.8753 23.74 71.6687 23.4333 71.522 23.1C71.3753 22.7533 71.302 22.3667 71.302 21.94C71.302 21.4467 71.4153 21 71.642 20.6C71.882 20.2 72.1953 19.8533 72.582 19.56C72.982 19.2667 73.4353 19.0467 73.942 18.9C74.462 18.74 74.9953 18.66 75.542 18.66C76.1287 18.66 76.6887 18.7267 77.222 18.86C77.7553 18.9933 78.2487 19.18 78.702 19.42C79.1687 19.66 79.582 19.9467 79.942 20.28L78.262 22.16C78.022 21.9333 77.7487 21.7333 77.442 21.56C77.1487 21.3733 76.842 21.2267 76.522 21.12C76.202 21.0133 75.9087 20.96 75.642 20.96C75.442 20.96 75.262 20.98 75.102 21.02C74.9553 21.0467 74.8287 21.1 74.722 21.18C74.6153 21.2467 74.5353 21.3333 74.482 21.44C74.4287 21.5333 74.402 21.6467 74.402 21.78C74.402 21.9133 74.4353 22.04 74.502 22.16C74.582 22.28 74.6887 22.38 74.822 22.46C74.9553 22.54 75.1687 22.6333 75.462 22.74C75.7553 22.8333 76.1553 22.9533 76.662 23.1C77.2887 23.2733 77.8287 23.4667 78.282 23.68C78.7353 23.8933 79.0953 24.1467 79.362 24.44C79.5753 24.6667 79.7353 24.9333 79.842 25.24C79.9487 25.5333 80.002 25.8533 80.002 26.2C80.002 26.88 79.8087 27.4867 79.422 28.02C79.0487 28.54 78.5287 28.9533 77.862 29.26C77.1953 29.5533 76.4353 29.7 75.582 29.7Z" fill="#212529"/>
<path d="M84.2244 29.5L80.7244 18.88H84.1044L86.0644 25.78L85.6444 25.7L87.8444 20.34H89.7244L92.0444 25.72L91.5844 25.76L93.5444 18.88H96.9244L93.3044 29.5H90.9444L88.6444 23.8L88.8844 23.84L86.5844 29.5H84.2244Z" fill="#212529"/>
<path d="M103.351 29.7C102.178 29.7 101.158 29.4667 100.291 29C99.4244 28.52 98.7511 27.8733 98.2711 27.06C97.7911 26.2333 97.5511 25.2933 97.5511 24.24C97.5511 23.4267 97.6844 22.68 97.9511 22C98.2177 21.32 98.5911 20.7333 99.0711 20.24C99.5511 19.7333 100.118 19.3467 100.771 19.08C101.438 18.8 102.164 18.66 102.951 18.66C103.698 18.66 104.378 18.7933 104.991 19.06C105.618 19.3267 106.158 19.7 106.611 20.18C107.064 20.66 107.411 21.2267 107.651 21.88C107.891 22.5333 107.998 23.2467 107.971 24.02L107.951 24.88H99.4911L99.0311 23.08H105.351L105.011 23.46V23.06C104.984 22.7267 104.878 22.4333 104.691 22.18C104.518 21.9133 104.284 21.7067 103.991 21.56C103.698 21.4133 103.364 21.34 102.991 21.34C102.471 21.34 102.024 21.4467 101.651 21.66C101.291 21.86 101.018 22.16 100.831 22.56C100.644 22.9467 100.551 23.4267 100.551 24C100.551 24.5867 100.671 25.1 100.911 25.54C101.164 25.9667 101.524 26.3 101.991 26.54C102.471 26.78 103.038 26.9 103.691 26.9C104.144 26.9 104.544 26.8333 104.891 26.7C105.251 26.5667 105.638 26.34 106.051 26.02L107.551 28.14C107.138 28.5 106.698 28.7933 106.231 29.02C105.764 29.2467 105.284 29.4133 104.791 29.52C104.311 29.64 103.831 29.7 103.351 29.7Z" fill="#212529"/>
<path d="M110.01 29.5V18.88H113.05L113.19 22.34L112.59 21.68C112.75 21.1067 113.01 20.5933 113.37 20.14C113.743 19.6867 114.176 19.3267 114.67 19.06C115.163 18.7933 115.69 18.66 116.25 18.66C116.49 18.66 116.71 18.68 116.91 18.72C117.123 18.76 117.316 18.8067 117.49 18.86L116.61 22.4C116.463 22.3067 116.263 22.2333 116.01 22.18C115.77 22.1133 115.516 22.08 115.25 22.08C114.956 22.08 114.683 22.1333 114.43 22.24C114.176 22.3333 113.963 22.4733 113.79 22.66C113.616 22.8467 113.476 23.0667 113.37 23.32C113.276 23.5733 113.23 23.86 113.23 24.18V29.5H110.01Z" fill="#212529"/>
</svg>

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -50,6 +50,14 @@ error:
other: "You can't vote for your own post!"
not_found:
other: "object not found"
verification_failed:
other: "verification failed"
email_or_password_incorrect:
other: "email or password incorrect"
old_password_verification_failed:
other: "the old password verification failed"
new_password_same_as_previous_setting:
other: "The new password is the same as the previous setting"
question:
not_found:
other: "question not found"

View File

@ -9,6 +9,7 @@ import (
"github.com/segmentfault/answer/internal/base/handler"
"github.com/segmentfault/answer/internal/base/middleware"
"github.com/segmentfault/answer/internal/base/reason"
"github.com/segmentfault/answer/internal/base/translator"
"github.com/segmentfault/answer/internal/schema"
"github.com/segmentfault/answer/internal/service"
"github.com/segmentfault/answer/internal/service/action"
@ -113,20 +114,24 @@ func (uc *UserController) UserEmailLogin(ctx *gin.Context) {
captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, schema.ActionRecord_Type_Login, ctx.ClientIP(), req.CaptchaID, req.CaptchaCode)
if !captchaPass {
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), gin.H{
"key": "captcha_code",
"value": "verification failed",
})
resp := schema.UserVerifyEmailErrorResponse{
Key: "captcha_code",
Value: "error.object.verification_failed",
}
resp.Value = translator.GlobalTrans.Tr(handler.GetLang(ctx), resp.Value)
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), resp)
return
}
resp, err := uc.userService.EmailLogin(ctx, req)
if err != nil {
_, _ = uc.actionService.ActionRecordAdd(ctx, schema.ActionRecord_Type_Login, ctx.ClientIP())
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), gin.H{
"key": "e_mail",
"value": "Email or password incorrect",
})
resp := schema.UserVerifyEmailErrorResponse{
Key: "e_mail",
Value: "error.object.email_or_password_incorrect",
}
resp.Value = translator.GlobalTrans.Tr(handler.GetLang(ctx), resp.Value)
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), resp)
return
}
uc.actionService.ActionRecordDel(ctx, schema.ActionRecord_Type_Login, ctx.ClientIP())
@ -149,10 +154,12 @@ func (uc *UserController) RetrievePassWord(ctx *gin.Context) {
}
captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, schema.ActionRecord_Type_Find_Pass, ctx.ClientIP(), req.CaptchaID, req.CaptchaCode)
if !captchaPass {
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), gin.H{
"key": "captcha_code",
"value": "verification failed",
})
resp := schema.UserVerifyEmailErrorResponse{
Key: "captcha_code",
Value: "error.object.verification_failed",
}
resp.Value = translator.GlobalTrans.Tr(handler.GetLang(ctx), resp.Value)
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), resp)
return
}
_, _ = uc.actionService.ActionRecordAdd(ctx, schema.ActionRecord_Type_Find_Pass, ctx.ClientIP())
@ -278,10 +285,13 @@ func (uc *UserController) UserVerifyEmailSend(ctx *gin.Context) {
captchaPass := uc.actionService.ActionRecordVerifyCaptcha(ctx, schema.ActionRecord_Type_Email, ctx.ClientIP(),
req.CaptchaID, req.CaptchaCode)
if !captchaPass {
handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), gin.H{
"key": "captcha_code",
"value": "verification failed",
})
resp := schema.UserVerifyEmailErrorResponse{
Key: "captcha_code",
Value: "error.object.verification_failed",
}
resp.Value = translator.GlobalTrans.Tr(handler.GetLang(ctx), resp.Value)
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), resp)
return
}
uc.actionService.ActionRecordAdd(ctx, schema.ActionRecord_Type_Email, ctx.ClientIP())
@ -312,17 +322,22 @@ func (uc *UserController) UserModifyPassWord(ctx *gin.Context) {
return
}
if !oldPassVerification {
handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), gin.H{
"key": "old_pass",
"value": "the old password verification failed",
})
resp := schema.UserVerifyEmailErrorResponse{
Key: "captcha_code",
Value: "error.object.old_password_verification_failed",
}
resp.Value = translator.GlobalTrans.Tr(handler.GetLang(ctx), resp.Value)
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), resp)
return
}
if req.OldPass == req.Pass {
handler.HandleResponse(ctx, errors.BadRequest(reason.RequestFormatError), gin.H{
"key": "pass",
"value": "The new password is the same as the previous setting",
})
resp := schema.UserVerifyEmailErrorResponse{
Key: "captcha_code",
Value: "error.object.new_password_same_as_previous_setting",
}
resp.Value = translator.GlobalTrans.Tr(handler.GetLang(ctx), resp.Value)
handler.HandleResponse(ctx, errors.BadRequest(reason.CaptchaVerificationFailed), resp)
return
}
err = uc.userService.UserModifyPassWord(ctx, req)

View File

@ -352,3 +352,8 @@ type UserVerifyEmailSendReq struct {
CaptchaID string `validate:"omitempty,gt=0,lte=500" json:"captcha_id"`
CaptchaCode string `validate:"omitempty,gt=0,lte=500" json:"captcha_code"`
}
type UserVerifyEmailErrorResponse struct {
Key string `json:"key"`
Value string `json:"value"`
}