NutzCN Logo
问答 新手邮件验证后更新信息的问题
发布于 2973天前 作者 dahaoqiu 1578 次浏览 复制 上一个帖子 下一个帖子
标签:

新手邮件验证通过后,显示为true,但是一点更新又变成了false,点更新的时候,我打了断点,
UserProfile profile。里面的profile.getEmailChecked==true,而old从数据库取出来的确实true。
是不是页面传值给后台有问题??但是除了emailChecked这个属性,别的都传过来了

12 回复

不是最新版?后台判断逻辑的问题,如果old是true且邮箱没变,就设置为true就好了

@wendal 是最新版,不过这个代码是从文档里面粘出来的,莫非文档不是最新版?

@dahaoqiu 贴你的代码看看

@wendal 这个代码是从书里面复制粘贴出来的

public void update(@Param("..")UserProfile profile, @Attr(scope=Scope.SESSION, value="me")int userId) {
if (profile == null)
return;
profile.setUserId(userId);//修正userId,防止恶意修改其他用户的信息
profile.setUpdateTime(new Date());
profile.setAvatar(null); // 不准通过这个方法更新
UserProfile old = get(userId);
// 检查email相关的更新
if (old.getEmail() == null) {
// 老的邮箱为null,所以新的肯定是未check的状态
profile.setEmailChecked(false);
} else {
if (profile.getEmail() == null) {
profile.setEmail(old.getEmail());
profile.setEmailChecked(old.isEmailChecked());
} else if (!profile.getEmail().equals(old.getEmail())) {
// 设置新邮箱,果断设置为未检查状态
profile.setEmailChecked(false);
}
}
Daos.ext(dao, FieldFilter.create(UserProfile.class, null, "avatar", true)).update(profile);
}

@wendal 是不是邮箱验证之后,用户更新的那个代码我没改???

看来是忘记更新了, 最后面加个else

	@RequiresUser
	@At
	@AdaptBy(type=JsonAdaptor.class)
	@Ok("void")
	public void update(@Param("..")UserProfile profile) {
		int userId = Toolkit.uid();
		if (profile == null)
			return;
		profile.setUserId(userId);//修正userId,防止恶意修改其他用户的信息
		profile.setUpdateTime(new Date());
		profile.setAvatar(null); // 不准通过这个方法更新
		UserProfile old = get();
		// 检查email相关的更新
		if (old.getEmail() == null) {
			// 老的邮箱为null,所以新的肯定是未check的状态
			profile.setEmailChecked(false);
		} else {
			if (profile.getEmail() == null) {
				profile.setEmail(old.getEmail());
				profile.setEmailChecked(old.isEmailChecked());
			} else if (!profile.getEmail().equals(old.getEmail())) {
				// 设置新邮箱,果断设置为未检查状态
				profile.setEmailChecked(false);
			} else {
				profile.setEmailChecked(old.isEmailChecked());
			}
		}
		Daos.ext(dao, FieldFilter.create(UserProfile.class, null, "avatar", true)).update(profile);
	}

@wendal 好的,另外还有个问题,那个用户列表页,怎么访问??按照书上面的写法,我始终访问不到

@wendal 这个代码不能直接用,不适合邮箱验证这个阶段,Toolkit这个类还没有uid()这个方法,
UserProfile old = get();
get这个方法里面也是有参数的
public UserProfile get(@Attr(scope=Scope.SESSION, value="me")int userId) {

恩恩,你替换一下就好了

添加回复
请先登陆
回到顶部