diff --git a/LivePPT/app/com/fever/liveppt/exception/ppt/PptNotPermissionDenyException.java b/LivePPT/app/com/fever/liveppt/exception/ppt/PptNotPermissionDenyException.java new file mode 100644 index 0000000..58ae20e --- /dev/null +++ b/LivePPT/app/com/fever/liveppt/exception/ppt/PptNotPermissionDenyException.java @@ -0,0 +1,17 @@ +package com.fever.liveppt.exception.ppt; + +import com.fever.liveppt.utils.StatusCode; + +/** + * Created with IntelliJ IDEA. + * User: Administrator + * Date: 13-9-28 + * Time: 下午9:37 + * To change this template use File | Settings | File Templates. + */ +public class PptNotPermissionDenyException extends PptException { + public PptNotPermissionDenyException() + { + super(StatusCode.PPT_NOT_PERMISSION_DENY,StatusCode.PPT_NOT_PERMISSION_DENY_MESSAGE); + } +} diff --git a/LivePPT/app/com/fever/liveppt/service/MeetingService.java b/LivePPT/app/com/fever/liveppt/service/MeetingService.java index e88bc6e..cc447b1 100644 --- a/LivePPT/app/com/fever/liveppt/service/MeetingService.java +++ b/LivePPT/app/com/fever/liveppt/service/MeetingService.java @@ -13,9 +13,10 @@ /** - * 会议服务 + * @author + * @version : v1.00 + * @Description : 会议操作接口 ,提供给controller层调用 * - * @author 梁博文 */ public interface MeetingService { diff --git a/LivePPT/app/com/fever/liveppt/service/PptService.java b/LivePPT/app/com/fever/liveppt/service/PptService.java index 5177014..4440c56 100644 --- a/LivePPT/app/com/fever/liveppt/service/PptService.java +++ b/LivePPT/app/com/fever/liveppt/service/PptService.java @@ -2,10 +2,7 @@ import com.fever.liveppt.exception.common.InternalErrorException; import com.fever.liveppt.exception.common.InvalidParamsException; -import com.fever.liveppt.exception.ppt.PptNotConvertedException; -import com.fever.liveppt.exception.ppt.PptNotExistedException; -import com.fever.liveppt.exception.ppt.PptNotSelfOwnException; -import com.fever.liveppt.exception.ppt.PptPageOutOfRangeException; +import com.fever.liveppt.exception.ppt.*; import com.fever.liveppt.models.Ppt; import com.fever.liveppt.models.User; import org.codehaus.jackson.JsonNode; @@ -14,9 +11,10 @@ import java.util.List; /** - * PPT服务 + * @author + * @version : v1.00 + * @Description : PPT操作接口 ,提供给controller层调用 * - * @author 梁博文 */ public interface PptService { @@ -31,7 +29,7 @@ public interface PptService { * @throws PptPageOutOfRangeException * @throws InternalErrorException */ - public byte[] getPptPage(Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException; + public byte[] getPptPage(String userEmail,Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException, PptNotPermissionDenyException; /** * 更新PPT转换状态 diff --git a/LivePPT/app/com/fever/liveppt/service/UserService.java b/LivePPT/app/com/fever/liveppt/service/UserService.java index e664a5c..7642bf4 100644 --- a/LivePPT/app/com/fever/liveppt/service/UserService.java +++ b/LivePPT/app/com/fever/liveppt/service/UserService.java @@ -2,13 +2,29 @@ import com.fever.liveppt.exception.common.CommonException; import com.fever.liveppt.exception.common.InvalidParamsException; +import com.fever.liveppt.exception.user.PasswordNotMatchException; import com.fever.liveppt.exception.user.UserException; import com.fever.liveppt.exception.user.UserNotExistedException; import com.fever.liveppt.models.User; import com.fever.liveppt.utils.ResultJson; +/** + * @author + * @version : v1.00 + * @Description : 用户操作接口 ,提供给controller层调用 + * + */ public interface UserService { + /** + * + * @param userEmail + * @param oldPassword + * @param newPassword + * @return + * @throws PasswordNotMatchException + */ + public ResultJson updatePassword(String userEmail,String oldPassword,String newPassword,String seed) throws PasswordNotMatchException; /** * 验证帐号密码 * diff --git a/LivePPT/app/com/fever/liveppt/service/impl/MeetingServiceImpl.java b/LivePPT/app/com/fever/liveppt/service/impl/MeetingServiceImpl.java index 3965680..7def923 100644 --- a/LivePPT/app/com/fever/liveppt/service/impl/MeetingServiceImpl.java +++ b/LivePPT/app/com/fever/liveppt/service/impl/MeetingServiceImpl.java @@ -1,3 +1,4 @@ + package com.fever.liveppt.service.impl; import com.fever.liveppt.exception.meeting.AttendingExistedException; @@ -20,6 +21,12 @@ import java.util.ArrayList; import java.util.List; +/** + * @author + * @version : v1.00 + * @Description : 会议操作接口实现 ,提供给service层调用 + * + */ public class MeetingServiceImpl implements MeetingService { @Override @@ -56,7 +63,7 @@ public ResultJson quitMeeting(String userEmail, Long meetingId) throws MeetingNo throw new MeetingNotAttendedException(); } for (Attender attender : user.attendents) { - if (attender.meeting.id == meetingId) { + if (attender.meeting.id.equals( meetingId)) { attender.delete(); isAttended = true; break; @@ -79,7 +86,7 @@ public ResultJson createMeeting(String userEmail, Long pptId, String topic) thro if (ppt == null) { throw new PptNotExistedException(); } - if (ppt.owner.id != founder.id) { + if (!ppt.owner.id.equals(founder.id)) { throw new MeetingPermissionDenyException(); } //新建发起的会议,并存入数据库 @@ -163,7 +170,7 @@ public ResultJson joinMeeting(String userEmail, Long meetingId) throws MeetingNo if (attendents != null) { for (Attender attending : attendents) { //已经加入 - if (attending.meeting.id == meeting.id) { + if (attending.meeting.id.equals(meeting.id)) { resultJson = ResultJson.simpleSuccess(); isAttended = true; break; @@ -189,7 +196,7 @@ public ResultJson setPage(String userEmail, Long meetingId, Long pageIndex) thro User user = User.find.where().eq("email", userEmail).findUnique(); - if (meeting.founder.id != user.id) { + if (!meeting.founder.id.equals(user.id)) { throw new MeetingPermissionDenyException(); } diff --git a/LivePPT/app/com/fever/liveppt/service/impl/PptServiceImpl.java b/LivePPT/app/com/fever/liveppt/service/impl/PptServiceImpl.java index 10a8367..4a3b495 100644 --- a/LivePPT/app/com/fever/liveppt/service/impl/PptServiceImpl.java +++ b/LivePPT/app/com/fever/liveppt/service/impl/PptServiceImpl.java @@ -8,10 +8,7 @@ import com.amazonaws.services.sqs.model.SendMessageRequest; import com.fever.liveppt.exception.common.InternalErrorException; import com.fever.liveppt.exception.common.InvalidParamsException; -import com.fever.liveppt.exception.ppt.PptNotConvertedException; -import com.fever.liveppt.exception.ppt.PptNotExistedException; -import com.fever.liveppt.exception.ppt.PptNotSelfOwnException; -import com.fever.liveppt.exception.ppt.PptPageOutOfRangeException; +import com.fever.liveppt.exception.ppt.*; import com.fever.liveppt.models.Attender; import com.fever.liveppt.models.Meeting; import com.fever.liveppt.models.Ppt; @@ -29,16 +26,50 @@ import java.util.LinkedList; import java.util.List; +/** + * @author + * @version : v1.00 + * @Description : PPT操作接口实现 ,提供给service层调用 + * + */ public class PptServiceImpl implements PptService { @Override - public byte[] getPptPage(Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException { + public byte[] getPptPage(String userEmail,Long pptId, Long pageId) throws PptNotExistedException, PptNotConvertedException, PptPageOutOfRangeException, InternalErrorException, PptNotPermissionDenyException { + boolean ifPermission = false; Ppt ppt = Ppt.find.byId(pptId); if (ppt == null) { throw new PptNotExistedException(); } + User user = User.find.where().eq("email", userEmail).findUnique(); + + for(Ppt userPpt: user.ppts) + { + if(pptId.equals(userPpt.id) ) + { + ifPermission = true; + break; + } + } + if(!ifPermission) + { + for (Attender attender : user.attendents) { + if(pptId == attender.meeting.ppt.id) + { + ifPermission = true; + break; + } + + } + } + + if(!ifPermission) + { + throw new PptNotPermissionDenyException(); + } + //检查是否已转换 if (!ppt.isConverted) { throw new PptNotConvertedException(); diff --git a/LivePPT/app/com/fever/liveppt/service/impl/UserServiceImpl.java b/LivePPT/app/com/fever/liveppt/service/impl/UserServiceImpl.java index 5e5f3c4..ac88e75 100644 --- a/LivePPT/app/com/fever/liveppt/service/impl/UserServiceImpl.java +++ b/LivePPT/app/com/fever/liveppt/service/impl/UserServiceImpl.java @@ -17,9 +17,25 @@ import java.util.HashMap; import java.util.Map; - +/** + * @author + * @version : v1.00 + * @Description : 用户操作接口实现 ,提供给service层调用 + * + */ public class UserServiceImpl implements UserService { - + @Override + public ResultJson updatePassword(String userEmail,String oldPassword,String newPassword,String seed) throws PasswordNotMatchException { + User user = User.find.where().eq("email", userEmail).findUnique(); + String userHashedPassword = Crypto.sign(user.password, seed.getBytes()); + if(!oldPassword.equals(userHashedPassword)) + { + throw new PasswordNotMatchException(); + } + user.password = Crypto.decryptAES(newPassword, seed); + user.save(); + return new ResultJson(StatusCode.SUCCESS, StatusCode.SUCCESS_MESSAGE, null); + } @Override public boolean isEmailExisted(String userEmail) throws CommonException, UserException { if (!TokenAgent.isEmailFormatValid(userEmail)) { diff --git a/LivePPT/app/com/fever/liveppt/utils/ControllerUtils.java b/LivePPT/app/com/fever/liveppt/utils/ControllerUtils.java index 402ca44..60b42b1 100644 --- a/LivePPT/app/com/fever/liveppt/utils/ControllerUtils.java +++ b/LivePPT/app/com/fever/liveppt/utils/ControllerUtils.java @@ -7,7 +7,7 @@ * User: simonlbw * Date: 13-8-28 * Time: 下午11:20 - * To change this template use File | Settings | File Templates. + * Description: controller层所用到的参数检查等方法 */ public class ControllerUtils { diff --git a/LivePPT/app/com/fever/liveppt/utils/DataJson.java b/LivePPT/app/com/fever/liveppt/utils/DataJson.java index 5c4ed60..c4a1170 100644 --- a/LivePPT/app/com/fever/liveppt/utils/DataJson.java +++ b/LivePPT/app/com/fever/liveppt/utils/DataJson.java @@ -5,7 +5,7 @@ * User: Zijing Lee * Date: 13-8-27 * Time: 上午10:42 - * To change this template use File | Settings | File Templates. + * Description: 封装Json格式的数据 */ import org.codehaus.jackson.JsonNode; diff --git a/LivePPT/app/com/fever/liveppt/utils/ResultJson.java b/LivePPT/app/com/fever/liveppt/utils/ResultJson.java index 94b2908..48bc4f9 100644 --- a/LivePPT/app/com/fever/liveppt/utils/ResultJson.java +++ b/LivePPT/app/com/fever/liveppt/utils/ResultJson.java @@ -6,7 +6,11 @@ import org.codehaus.jackson.node.ObjectNode; /** - * 封装数据方向接口的自定义JSON格式 + * Created with IntelliJ IDEA. + * User: Zijing Lee + * Date: 13-9-27 + * Time: 上午10:42 + * Description: 封装数据方向接口的自定义JSON格式,即接口返回数据的JSON格式 */ public class ResultJson extends ObjectNode { public final static String KEY_DATA = "data"; diff --git a/LivePPT/app/com/fever/liveppt/utils/StatusCode.java b/LivePPT/app/com/fever/liveppt/utils/StatusCode.java index 698fefa..0bf3038 100644 --- a/LivePPT/app/com/fever/liveppt/utils/StatusCode.java +++ b/LivePPT/app/com/fever/liveppt/utils/StatusCode.java @@ -1,5 +1,11 @@ package com.fever.liveppt.utils; - +/** + * Created with IntelliJ IDEA. + * User: Zijing Lee + * Date: 13-9-27 + * Time: 上午12:43 + * Description: 异常状态码以及异常返回信息静态变量定义 + */ public class StatusCode { //一切正常 public final static int SUCCESS = 0; @@ -44,6 +50,9 @@ public class StatusCode { //指定PPT并非用户自己所拥有 public final static int PPT_NOT_SELF_OWN = -305; public final static String PPT_NOT_SELF_OWN_MESSAGE = "ppt not of user own"; + //用户没有权限操作该PPT + public final static int PPT_NOT_PERMISSION_DENY = -306; + public final static String PPT_NOT_PERMISSION_DENY_MESSAGE = "not have permission to operate the ppt" ; //*******************MEETING类型错误***************** //Meeting不存在 public final static int MEETING_NOT_EXISTED = -401; diff --git a/LivePPT/app/com/fever/liveppt/utils/TokenAgent.java b/LivePPT/app/com/fever/liveppt/utils/TokenAgent.java index f818358..00f582a 100644 --- a/LivePPT/app/com/fever/liveppt/utils/TokenAgent.java +++ b/LivePPT/app/com/fever/liveppt/utils/TokenAgent.java @@ -12,7 +12,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; - +/** + * Created with IntelliJ IDEA. + * User: Zijing Lee + * Date: 13-9-27 + * Time: 上午12:43 + * Description: 关于用户登陆后token的操作,包括token的检验,根据token获取用户,生成token等。 + */ public class TokenAgent { public static Pattern emailPattern = Pattern.compile("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\\.([a-zA-Z0-9_-])+)+$"); diff --git a/LivePPT/app/controllers/MeetingController.java b/LivePPT/app/controllers/MeetingController.java index 5306cbb..7483fc0 100644 --- a/LivePPT/app/controllers/MeetingController.java +++ b/LivePPT/app/controllers/MeetingController.java @@ -1,3 +1,4 @@ + package controllers; import akka.actor.Cancellable; @@ -29,11 +30,20 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; - +/** + * @author + * @version : v1.00 + * @Description : 会议controller 提供给前端以及手机端会议操作的接口 + * + */ public class MeetingController extends Controller { @Inject MeetingService meetingService; + /** + * 会议同步PPT + * @return + */ public static WebSocket viewWebsocket() { return new WebSocket() { @@ -113,8 +123,11 @@ public void invoke() { /** * 发起新会议 - * * @return + * @exception TokenInvalidException + * @exception InvalidParamsException + * @exception PptNotExistedException + * @exception MeetingPermissionDenyException */ public Result createMeeting() { ResultJson resultJson; @@ -163,8 +176,11 @@ public Result createMeeting() { /** * 删除用户自己发起的会议 - * * @return + * @exception TokenInvalidException + * @exception InvalidParamsException + * @exception MeetingNotExistedException + * @exception MeetingPermissionDenyException */ public Result deleteMeeting() { ResultJson resultJson; @@ -208,7 +224,10 @@ public Result deleteMeeting() { /** * 修改用户自己发起的会议 - * + * @exception TokenInvalidException + * @exception InvalidParamsException + * @exception MeetingNotExistedException + * @exception MeetingPermissionDenyException * @return */ public Result updateMeeting() { @@ -269,8 +288,9 @@ public Result updateMeeting() { /** * 加入观看指定会议 - * * @return + * @exception TokenInvalidException + * @exception */ public Result joinMeeting() { ResultJson resultJson; @@ -314,8 +334,10 @@ public Result joinMeeting() { /** * 退出观看指定会议 - * * @return + * @exception TokenInvalidException + * @exception InvalidParamsException + * @exception MeetingException */ public Result quitMeeting() { ResultJson resultJson; @@ -357,8 +379,12 @@ public Result quitMeeting() { /** * 设置会议的PPT页码 - * * @return + * @exception TokenInvalidException + * @exception InvalidParamsException + * @exception MeetingNotExistedException + * @exception PptPageOutOfRangeException + * @exception MeetingPermissionDenyException */ public Result setPage() { ResultJson resultJson; @@ -414,8 +440,9 @@ public Result setPage() { /** * 获取用户所有自己发起的会议 - * * @return + * @exception TokenInvalidException + * @exception InvalidParamsException */ public Result getMyFoundedMeetings() { ResultJson resultJson; @@ -443,8 +470,9 @@ public Result getMyFoundedMeetings() { /** * 获取用户所有观看的会议 - * * @return + * @exception TokenInvalidException + * @exception InvalidParamsException */ public Result getMyAttendingMeeting() { ResultJson resultJson; @@ -473,8 +501,9 @@ public Result getMyAttendingMeeting() { /** * 获取指定会议信息 - * * @return + * @exception InvalidParamsException + * @exception MeetingNotExistedException */ public Result getMeetingInfo() { ResultJson resultJson; diff --git a/LivePPT/app/controllers/PptController.java b/LivePPT/app/controllers/PptController.java index d4c041e..932f812 100644 --- a/LivePPT/app/controllers/PptController.java +++ b/LivePPT/app/controllers/PptController.java @@ -1,3 +1,4 @@ + package controllers; import com.fever.liveppt.exception.common.CommonException; @@ -30,7 +31,12 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; - +/** + * @author + * @version : v1.00 + * @Description : PPT controller 提供给前端以及手机端PPT操作的接口 + * + */ public class PptController extends Controller { //PPT和PPTX文件的ContentType @@ -46,8 +52,9 @@ public class PptController extends Controller { /** * 获取用户所有PPT的列表 - * * @return + * @exception InvalidParamsException + * @exception TokenInvalidException */ public Result infoAll() { ResultJson resultJson; @@ -77,8 +84,9 @@ public Result infoAll() { /** * 获取指定PPT的信息 - * * @return + * @exception PptNotExistedException + * @exception InvalidParamsException */ public Result getPptInfo() { ResultJson resultJson; @@ -122,10 +130,14 @@ public Result getPptInfo() { /** * 获取指定PPT和页码的图片 - * * @return + * @exception InvalidParamsException + * @exception PptNotExistedException + * @exception NumberFormatException */ public Result getPptPageImage() { + + //如果含有IF_MODIFIED_SINCE报头则返回NOT_MODIFIED String ifModifiedSince = request().getHeader(Controller.IF_MODIFIED_SINCE); if (ifModifiedSince != null && ifModifiedSince.length() > 0) { @@ -134,6 +146,8 @@ public Result getPptPageImage() { ResultJson resultJson; try { + //验证Token并提取userEmail + String userEmail = TokenAgent.validateTokenFromHeader(request()); //获取GET参数 Map params = request().queryString(); if (params == null || params.size() == 0) { @@ -156,7 +170,7 @@ public Result getPptPageImage() { //尝试获取指定页码图像数据 - byte[] imageByte = pptService.getPptPage(pptId, page); + byte[] imageByte = pptService.getPptPage(userEmail,pptId, page); if (imageByte.length > 0) { //成功获取图像数据 @@ -184,6 +198,13 @@ public Result getPptPageImage() { return ok(resultJson); } + /** + * 上传PPT + * @return + * @exception InvalidParamsException + * @exception PptFileInvalidTypeException + * @exception UserException + */ public Result pptUpload() { ResultJson resultJson; try { @@ -234,6 +255,13 @@ public Result pptUpload() { return ok(resultJson); } + /** + * 删除PPT + * @return + * @exception InvalidParamsException + * @exception PptNotExistedException + * @exception UserException + */ public Result pptDelete() { ResultJson resultJson; try { @@ -276,7 +304,6 @@ public Result pptDelete() { /** * 更新PPT转换的状态 - * * @return */ public Result convertstatus() { diff --git a/LivePPT/app/controllers/UserController.java b/LivePPT/app/controllers/UserController.java index 6ce8c00..f12fb91 100644 --- a/LivePPT/app/controllers/UserController.java +++ b/LivePPT/app/controllers/UserController.java @@ -1,13 +1,22 @@ +/** + * @author + * @version : v1.00 + * @Description : User controller 提供给前端以及手机端用户操作的接口 + * + */ package controllers; import com.fever.liveppt.exception.common.CommonException; import com.fever.liveppt.exception.common.InvalidParamsException; +import com.fever.liveppt.exception.common.TokenInvalidException; +import com.fever.liveppt.exception.user.PasswordNotMatchException; import com.fever.liveppt.exception.user.UserException; import com.fever.liveppt.exception.user.UserExistedException; import com.fever.liveppt.service.UserService; import com.fever.liveppt.utils.ControllerUtils; import com.fever.liveppt.utils.ResultJson; import com.fever.liveppt.utils.StatusCode; +import com.fever.liveppt.utils.TokenAgent; import com.google.inject.Inject; import play.Logger; import play.libs.Crypto; @@ -20,10 +29,53 @@ public class UserController extends Controller { @Inject UserService userService; + public Result updatePassword(){ + Map params = request().body().asFormUrlEncoded(); + ResultJson resultJson; + try { + //验证Token并提取userEmail + String userEmail = TokenAgent.validateTokenFromHeader(request()); + if (null == params) { + throw new InvalidParamsException(); + } + + //oldPassword + if (!ControllerUtils.isFieldNotNull(params, "oldPassword")) { + throw new InvalidParamsException(); + } + + //newPassword + if (!ControllerUtils.isFieldNotNull(params, "newPassword")) { + throw new InvalidParamsException(); + } + + //seed + if (!ControllerUtils.isFieldNotNull(params, "seed")) { + throw new InvalidParamsException(); + } + + // 获取参数 + String oldPassword = params.get("oldPassword")[0]; + String newPassword = params.get("newPassword")[0]; + String seed = params.get("seed")[0]; + + resultJson = userService.updatePassword(userEmail,oldPassword,newPassword,seed); + } catch (TokenInvalidException e) { + resultJson = new ResultJson(e); + } catch (PasswordNotMatchException e) { + resultJson = new ResultJson(e); + } catch (InvalidParamsException e) { + resultJson = new ResultJson(e); + } + + //返回JSON + return ok(resultJson); + } /** - * 检验用户Email是否被占用 - * + * 检查用户Email是否被占用 * @return + * @exception InvalidParamsException + * @exception UserException */ public Result checkEmail() { Map params = request().body().asFormUrlEncoded(); @@ -63,8 +115,9 @@ public Result checkEmail() { /** * 用户登录接口 - * * @return + * @exception InvalidParamsException + * @exception UserException */ public Result login() { //获取POST参数 @@ -117,8 +170,9 @@ public Result login() { /** * 用户注册接口 - * * @return + * @exception InvalidParamsException + * @exception UserException */ public Result register() { //获取POST参数 diff --git a/LivePPT/conf/routes b/LivePPT/conf/routes index 2b52c2b..3f034dd 100644 --- a/LivePPT/conf/routes +++ b/LivePPT/conf/routes @@ -24,7 +24,8 @@ POST /user/register @controllers.UserController.register() POST /user/login @controllers.UserController.login() #验证用户Email是否被占用 POST /user/check_email @controllers.UserController.checkEmail() - +#修改用户密码 +POST /user/update_password @controllers.UserController.updatePassword() ### #PPT方向接口 diff --git "a/LivePPT/doc/CloudSlides\344\270\200\350\210\254\347\272\246\345\256\232\344\270\216\346\216\245\345\217\243\346\226\207\346\241\243.docx" "b/LivePPT/doc/CloudSlides\344\270\200\350\210\254\347\272\246\345\256\232\344\270\216\346\216\245\345\217\243\346\226\207\346\241\243.docx" index bebc731..007f0b2 100644 Binary files "a/LivePPT/doc/CloudSlides\344\270\200\350\210\254\347\272\246\345\256\232\344\270\216\346\216\245\345\217\243\346\226\207\346\241\243.docx" and "b/LivePPT/doc/CloudSlides\344\270\200\350\210\254\347\272\246\345\256\232\344\270\216\346\216\245\345\217\243\346\226\207\346\241\243.docx" differ