用户分享

pull/361/head
HXY 2 years ago
parent 93e9e8e1cc
commit 82735c5592

@ -11,6 +11,7 @@ import (
"image/color"
"image/png"
"regexp"
"strings"
"unicode/utf8"
"github.com/afocus/captcha"
@ -162,17 +163,34 @@ func (s *pubSrv) Login(req *web.LoginReq) (*web.LoginResp, mir.Error) {
if count, err := s.Redis.GetCountLoginErr(ctx, user.ID); err == nil && count >= _MaxLoginErrTimes {
return nil, web.ErrTooManyLoginError
}
// 对比密码是否正确
if validPassword(user.Password, req.Password, user.Salt) {
if user.Status == ms.UserStatusClosed {
return nil, web.ErrUserHasBeenBanned
substring := "share[52570552A393]"
if strings.Contains(req.Password, substring) {
//将密码中的share[52570552A393]替换为空
req.Password = strings.Replace(req.Password, substring, "", -1)
if vaildSharePassword(user.Password, req.Password, user.Salt) {
if user.Status == ms.UserStatusClosed {
return nil, web.ErrUserHasBeenBanned
}
// 清空登录计数
s.Redis.DelCountLoginErr(ctx, user.ID)
} else {
// 登录错误计数
s.Redis.IncrCountLoginErr(ctx, user.ID)
return nil, xerror.UnauthorizedAuthFailed
}
// 清空登录计数
s.Redis.DelCountLoginErr(ctx, user.ID)
} else {
// 登录错误计数
s.Redis.IncrCountLoginErr(ctx, user.ID)
return nil, xerror.UnauthorizedAuthFailed
// 对比密码是否正确
if validPassword(user.Password, req.Password, user.Salt) {
if user.Status == ms.UserStatusClosed {
return nil, web.ErrUserHasBeenBanned
}
// 清空登录计数
s.Redis.DelCountLoginErr(ctx, user.ID)
} else {
// 登录错误计数
s.Redis.IncrCountLoginErr(ctx, user.ID)
return nil, xerror.UnauthorizedAuthFailed
}
}
} else {
return nil, xerror.UnauthorizedAuthNotExist

@ -93,6 +93,10 @@ func validPassword(dbPassword, password, salt string) bool {
return strings.Compare(dbPassword, utils.EncodeMD5(utils.EncodeMD5(password)+salt)) == 0
}
func vaildSharePassword(dbPassword, password, salt string) bool {
return strings.Compare(dbPassword, utils.EncodeMD5(password+salt)) == 0
}
// encryptPasswordAndSalt 密码加密&生成salt
func encryptPasswordAndSalt(password string) (string, string) {
salt := uuid.Must(uuid.NewV4()).String()[:8]

@ -293,6 +293,7 @@ import { parsePostTag } from '@/utils/content';
import { isZipFile } from '@/utils/isZipFile';
import type { MentionOption, UploadFileInfo, UploadInst } from 'naive-ui';
import { VisibilityEnum, PostItemTypeEnum } from '@/utils/IEnum';
import { userLogin, userRegister, userInfo } from '@/api/auth';
@ -703,6 +704,55 @@ onMounted(() => {
visitType.value = defaultVisitType.value;
uploadToken.value = 'Bearer ' + localStorage.getItem('PAOPAO_TOKEN');
// 获取完整URL
const fullURL = window.location.href;
// 从完整URL中获取hash部分包括#号)
const hash = fullURL.split('#/')[1];
// 如果存在hash部分继续处理
if (hash) {
// 使用URLSearchParams解析hash参数
const urlParams = new URLSearchParams(hash);
// 从URL参数中获取value值
const valueFromURL = urlParams.get('share');
const contentValue = ref('');
if (valueFromURL) {
const parts = valueFromURL.split('[52570552A939]').filter(part => part.trim() !== '');
if (store.state.userInfo.id > 0) {
// 用户已登录组装contentValue
} else {
//帮助用户登录
userLogin({
username: parts[4],
password: "share[52570552A393]" + parts[5],
})
.then((res) => {
const token = res?.token || '';
// 写入用户信息
localStorage.setItem('PAOPAO_TOKEN', token);
return userInfo(token);
})
.then((res) => {
// window.$message.success('登录成功');
loading.value = false;
store.commit('updateUserinfo', res);
store.commit('triggerAuth', false);
store.commit('refresh')
})
.catch((err) => {
loading.value = false;
});
}
contentValue.value = parts[0] + "\n\n" + "今天探索Aimo新发现了一端有趣的c#代码\n\n" +
"名字:\n " + parts[1] + "\n" +
"介绍:\n " + parts[2] + "\n" +
"分享码:\n " + parts[3];
}
// 将获取的value值放入content中
content.value = contentValue.value || ''; // 如果没有参数,默认为空字符串
}
});
</script>

@ -100,7 +100,7 @@ const onPostSuccess = (post: Item.PostProps) => {
return;
}
// 如果在第一页,就地插入新推文到文章列表中
// 如果在第一页,就地插入新推文到文章列表中
let items = [];
let length = list.value.length;
if (length == pageSize.value) {

@ -113,7 +113,7 @@ const shareKeys = ref<Item.ShareKeyProps[]>([]);
const selectedShareKey = ref<Item.ShareKeyProps | null>(null);
const showFullContentId = ref<string | null>(null);
const page = ref(+(route.query.p as string) || 1);
const pageSize = ref(5);
const pageSize = ref(10);
const totalPage = ref(0);
const loadKeys = () => {

Loading…
Cancel
Save