Commits

Anonymous committed 24490db

0707@home

Comments (0)

Files changed (8)

src/info/mrchen/gae/blog/Dao.java

 		jpaTemplate = new JpaTemplate(entityManager);
 	}
 
-	Class<T> persistanceClass;
+	protected Class<T> persistanceClass;
 
 	public void Delete(T object) {
 		jpaTemplate.remove(object);
 
 	}
 
-	public List GetByQueryString(String queryString) {
+	public List getByQueryString(String queryString) {
 		return entityManager.createQuery(queryString).getResultList();
 	}
 

src/info/mrchen/gae/blog/controller/UserProfileController.java

+package info.mrchen.gae.blog.controller;
+
+import info.mrchen.gae.blog.dao.UserInfoService;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import com.google.appengine.api.users.UserService;
+import com.google.appengine.api.users.UserServiceFactory;
+
+@Controller
+public class UserProfileController {
+	UserService userService = UserServiceFactory.getUserService();
+
+	@Autowired
+	UserInfoService userInfoService;
+
+	@RequestMapping("/profile/index.do")
+	public void show(Model model) {
+		model.addAttribute("username", userInfoService.getMyProfile(userService.getCurrentUser()));
+	}
+}

src/info/mrchen/gae/blog/dao/UserInfoDao.java

 import info.mrchen.gae.blog.Dao;
 import info.mrchen.gae.blog.pojo.Userinfo;
 
+import java.util.List;
+
 import org.springframework.stereotype.Component;
 
+import com.google.appengine.api.users.User;
+
 @Component
 public class UserInfoDao extends Dao<Userinfo> {
+	public boolean checkPassword(String username, String password) {
+		String queryString = "from User where user=?";
+		List<Userinfo> l = this.getByQueryString(queryString);
+		return l.size() > 0 && l.get(0).getPassword().equals(password);
+	}
 
+	public Userinfo get(User user) {
+
+		return null;
+	}
 }

src/info/mrchen/gae/blog/dao/UserInfoService.java

+package info.mrchen.gae.blog.dao;
+
+import info.mrchen.gae.blog.pojo.Userinfo;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.google.appengine.api.users.User;
+
+public class UserInfoService {
+
+	@Autowired
+	UserInfoDao userInfoDao;
+
+	public boolean checkPassword(String username, String password) {
+		if (username == null || username.length() < 1) {
+			return false;
+		}
+		return userInfoDao.checkPassword(username, password);
+
+	}
+
+	public Userinfo getMyProfile(User user) {
+		Userinfo userInfo = userInfoDao.get(user);
+		if (userInfo == null) {
+			Userinfo userInfo1 = new Userinfo();
+			userInfo.setUser(user);
+			userInfoDao.save(userInfo1);
+			return userInfo1;
+		} else {
+			return userInfo;
+		}
+	}
+}

src/info/mrchen/gae/blog/pojo/Userinfo.java

-package info.mrchen.gae.blog.pojo;
-
-import javax.jdo.annotations.IdGeneratorStrategy;
-import javax.jdo.annotations.IdentityType;
-import javax.jdo.annotations.PersistenceCapable;
-import javax.jdo.annotations.Persistent;
-import javax.jdo.annotations.PrimaryKey;
-
-import com.google.appengine.api.users.User;
-
-@PersistenceCapable(identityType = IdentityType.APPLICATION)
-public class Userinfo {
-	@PrimaryKey
-	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
-	private Long id;
-
-	@Persistent
-	private User owner;
-
-	@Persistent
-	private String username;
-	
-	@Persistent
-	private String password;
-
-}

src/info/mrchen/gae/blog/service/CategoryService.java

 
 	@Autowired
 	CategoryDao categoryDao;
-
+	
 	public Category get(Long CategoryID) {
 		return categoryDao.get(CategoryID);
 	}

src/info/mrchen/gae/blog/service/SysconfService.java

 	public Sysconf get(User user, String key) {
 		return sysconfDao.get(user, key);
 	}
+
+	public String getValue(String sysconfKey) {
+		Sysconf conf = this.get(sysconfKey);
+		if (conf != null && conf.getValue() != null) {
+			return conf.getValue();
+		} else {
+			return null;
+		}
+	}
 }

src/info/mrchen/gae/blog/xmlrpc/handder/MetaWeblogHandler.java

 package info.mrchen.gae.blog.xmlrpc.handder;
 
+import info.mrchen.gae.blog.dao.UserInfoDao;
+import info.mrchen.gae.blog.dao.UserInfoService;
 import info.mrchen.gae.blog.pojo.Category;
 import info.mrchen.gae.blog.service.ArticleService;
 import info.mrchen.gae.blog.service.CategoryService;
+import info.mrchen.gae.blog.service.SysconfService;
 import info.mrchen.gae.blog.xmlrpc.MetaweblogApiField;
 
 import java.util.ArrayList;
 @Component
 public class MetaWeblogHandler implements XmlRpcHandler, MetaweblogApiField {
 
+	private static final String SYSCONF_BLOG_NAME = null;
+
 	@Autowired
 	CategoryService categoryService;
 
 	@Autowired
 	ArticleService articleService;
 
+	@Autowired
+	SysconfService sysconfService;
+
+	@Autowired
+	UserInfoService userInfoService;
+
 	public Map<String, Object>[] getUsersBlogs(String appkey, String username, String password) {
 		Map<String, Object> blog = new HashMap<String, Object>();
+		if (userInfoService.checkPassword(username, password)) {
+		} else {
+			return new Map[] {};
+		}
 
 		String url = "http://localhost:8888/";
 		if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
 		}
 		blog.put(BLOG_URL, url);
 		blog.put(BLOG_BLOGID, "1");
-		blog.put(BLOG_BLOGNAME, "mrchen-gae-blog");
+		String blogTitle = sysconfService.getValue(SYSCONF_BLOG_NAME);
+
+		blog.put(BLOG_BLOGNAME, blogTitle);
 		return new Map[] { blog };
 	}