Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/brookshi/Hitchhiker
Browse files Browse the repository at this point in the history
  • Loading branch information
brookshi committed Mar 12, 2018
2 parents b5193cd + f32b0c7 commit 09f210c
Show file tree
Hide file tree
Showing 101 changed files with 1,720 additions and 734 deletions.
80 changes: 5 additions & 75 deletions api/common/message.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,12 @@
import { Setting } from '../utils/setting';

export class Message {
static userEmailRepeat: string = 'email is taken';
static userEmailFormatError: string = 'email format error';
static userPasswordFormatError: string = 'password format error';
static userNameFormatError: string = 'name format error';
static userCreateSuccess: string = 'create user success';
static userCreateFailed: string = 'create user failed';
static userCheckFailed: string = 'email or password error';
static accountNotActive: string = 'account is not active, please active it in your email';
static regSuccess = Setting.instance.needRegisterMailConfirm ? 'register success, please active your account in your email' : 'register success, please login';
static userLogout: string = 'logout success';
static userLoginSuccess: string = 'login success';
static userNotExist: string = 'user does not exist';
static userOldPwdIncorrect: string = 'old password is incorrect';
static userChangePwdSuccess: string = 'change password success';
static findPwdSuccess: string = 'a new password have send to your mail';
static regConfirmFailedUserNotExist: string = 'check failed, user does not exist';
static regConfirmFailedUserConfirmed: string = 'user was confirmed';
static regConfirmFailedExpired: string = 'verification url was expired';
static regConfirmFailedInvalid: string = 'verification url was invalid';
static regConfirmSuccess: string = 'account is activated, you can use it to login now';

static inviterNotExist: string = 'inviter does not exist';
static emailsAtLeastOne: string = 'at least one email';
static en = require('../locales/en.json');

static envCreateFailed: string = 'create environment failed';
static envCreateSuccess: string = 'create environment success';
static envUpdateSuccess: string = 'update environment success';
static envDeleteSuccess: string = 'delete environment success';
static envNotExist: string = 'environment does not exist';
static zh = require('../locales/zh.json');

static projectSaveSuccess: string = 'project save success';
static projectUpdateSuccess: string = 'project update success';
static projectQuitSuccess: string = 'quit project success';
static projectNotExist: string = 'project does not exist';
static projectDisbandNeedOwner: string = 'only project owner can disband this project';
static projectDisbandSuccess: string = 'disband project success';
static projectDeleteSuccess: string = 'delete project success';
static emailsAllInProject: string = 'emails are all in this project already';
static alreadyInProject: string = 'already in this project';
static joinProjectSuccess: string = 'join project success';
static rejectProjectSuccess: string = 'reject invite success';
static updateLocalhostMappingSuccess: string = 'update localhost mapping success';
static createLocalhostMappingSuccess: string = 'create localhost mapping success';
static updateGlobalFuncSuccess: string = 'update global function success';
static deleteProjectFileSuccess: string = 'delete project file success';

static collectionCreateFailed: string = 'create collection failed';
static collectionCreateSuccess: string = 'create collection success';
static collectionUpdateSuccess: string = 'update collection success';
static collectionNotExist: string = 'collection does not exist';
static collectionDeleteSuccess: string = 'collection delete success';

static recordCreateFailed: string = 'create record failed';
static recordCreateFailedOnName: string = 'record name is incorrect';
static recordSortSuccess: string = 'sort records success';
static recordSaveSuccess: string = 'record save success';
static recordDeleteSuccess: string = 'record delete success';

static scheduleCreateSuccess: string = 'create schedule success';
static scheduleCreateFailed: string = 'create schedule failed';
static scheduleUpdateSuccess: string = 'update schedule success';
static scheduleDeleteSuccess: string = 'delete schedule success';
static scheduleNotExist: string = 'schedule id does not exist';

static stressCreateSuccess: string = 'create stress test success';
static stressCreateFailed: string = 'create stress test failed';
static stressUpdateSuccess: string = 'update stress test success';
static stressDeleteSuccess: string = 'delete stress test success';
static stressNotExist: string = 'stress test case does not exist';
static stressNoRecords: string = 'stress test case does not have any valid request';

static apiNotExist: string = 'this api does not exist';

static sessionInvalid: string = 'session is invalid';

static tokenInvalid: string = 'token is invalid';

static importPostmanSuccess: string = 'import postman data success';
static get(id: string) {
return this[Setting.instance.appLanguage][id];
}
}
2 changes: 1 addition & 1 deletion api/controllers/collection_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ export default class CollectionController extends BaseController {
async importFromPostman(ctx: Koa.Context, @PathParam('projectid') projectId: string, @BodyParam info: any): Promise<ResObject> {
const user = SessionService.getUser(ctx);
await Importer.do(info, projectId, user);
return { success: true, message: Message.importPostmanSuccess };
return { success: true, message: Message.get('importPostmanSuccess') };
}
}
16 changes: 8 additions & 8 deletions api/controllers/project_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class ProjectController extends BaseController {
const data = <{ info: InviteToProjectToken, user: User, project: Project }>validateRst.result;

if (data.user.projects.find(o => o.id === projectId)) {
return Message.alreadyInProject;
return Message.get('alreadyInProject');
}

data.user.projects.push(data.project);
Expand All @@ -92,24 +92,24 @@ export default class ProjectController extends BaseController {
const data = <{ info: InviteToProjectToken, user: User, project: Project }>validateRst.result;
MailService.rejectProjectMail(data.info.inviterEmail, data.info.userEmail, data.project.name);

return Message.rejectProjectSuccess;
return Message.get('rejectProjectSuccess');
}

private async validateInfo(projectId: string, token: string): Promise<ResObject> {
if (!TokenService.isValidToken(token)) {
return { success: false, message: Message.tokenInvalid };
return { success: false, message: Message.get('tokenInvalid') };
}

const info = TokenService.parseToken<InviteToProjectToken>(token);

if (projectId !== info.projectId) {
return { success: false, message: Message.tokenInvalid };
return { success: false, message: Message.get('tokenInvalid') };
}

const project = await ProjectService.getProject(projectId);

if (!project) {
return { success: false, message: Message.projectNotExist };
return { success: false, message: Message.get('projectNotExist') };
}

TokenService.removeToken(token);
Expand All @@ -131,12 +131,12 @@ export default class ProjectController extends BaseController {
const project = await ProjectService.getProject(projectId, false, true);

if (!project) {
return { success: false, message: Message.projectNotExist };
return { success: false, message: Message.get('projectNotExist') };
}

emailArr = _.difference(emailArr, project.members.map(t => t.email));
if (emailArr.length === 0) {
return { success: false, message: Message.emailsAllInProject };
return { success: false, message: Message.get('emailsAllInProject') };
}

const user = (<any>ctx).session.user;
Expand Down Expand Up @@ -176,7 +176,7 @@ export default class ProjectController extends BaseController {
@DELETE('/project/:projectId/file/:type/:name')
deleteProjectFile( @PathParam('projectId') projectId: string, @PathParam('type') type: ProjectFolderType, @PathParam('name') name: string): ResObject {
ProjectDataService.instance.removeFile(type, projectId, name);
return { success: true, message: Message.deleteProjectFileSuccess };
return { success: true, message: Message.get('deleteProjectFileSuccess') };
}

@POST('/project/:projectId/:type')
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/schedule_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ScheduleController extends BaseController {
async run( @PathParam('id') id: string): Promise<ResObject> {
const schedule = await ScheduleService.getById(id);
if (!schedule) {
return { success: false, message: Message.scheduleNotExist };
return { success: false, message: Message.get('scheduleNotExist') };
}

new ScheduleRunner().runSchedule(schedule, null, false);
Expand Down
20 changes: 10 additions & 10 deletions api/controllers/user_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class UserController extends BaseController {

SessionService.login(ctx, (<User>checkLogin.result.user).id);

checkLogin.message = Message.userLoginSuccess;
checkLogin.message = Message.get('userLoginSuccess');
(<User>checkLogin.result.user).password = undefined;

return checkLogin;
Expand All @@ -64,7 +64,7 @@ export default class UserController extends BaseController {
@GET('/user/logout')
logout(ctx: Koa.Context): ResObject {
SessionService.logout(ctx);
return { success: true, message: Message.userLogout };
return { success: true, message: Message.get('userLogout') };
}

@PUT('/user/password')
Expand All @@ -76,7 +76,7 @@ export default class UserController extends BaseController {

const user = <User>(<any>ctx).session.user;
if (user.password !== info.oldPassword) {// TODO: md5
return { success: false, message: Message.userOldPwdIncorrect };
return { success: false, message: Message.get('userOldPwdIncorrect') };
}

return await UserService.changePwd(user.id, info.newPassword);
Expand All @@ -91,7 +91,7 @@ export default class UserController extends BaseController {

const user = await UserService.getUserByEmail(email);
if (!user) {
return { success: false, message: Message.userNotExist };
return { success: false, message: Message.get('userNotExist') };
}

const newPwd = StringUtil.generateShortId();
Expand All @@ -100,7 +100,7 @@ export default class UserController extends BaseController {
return checkRst;
}

let rst: ResObject = { success: true, message: Message.findPwdSuccess };
let rst: ResObject = { success: true, message: Message.get('findPwdSuccess') };
await MailService.findPwdMail(email, newPwd).catch(err => rst = { success: false, message: err.message });

return rst;
Expand All @@ -110,27 +110,27 @@ export default class UserController extends BaseController {
async regConfirm(ctx: Koa.Context, @QueryParam('id') id: string, @QueryParam('token') token: string): Promise<string> {
const user = await UserService.getUserById(id);
if (!user) {
return Message.regConfirmFailedUserNotExist;
return Message.get('regConfirmFailedUserNotExist');
}

if (user.isActive) {
return Message.regConfirmFailedUserConfirmed;
return Message.get('regConfirmFailedUserConfirmed');
}

const json = StringUtil.decrypt(token);
const info = <RegToken>JSON.parse(json);

if (!info || info.host !== Setting.instance.appHost) {
return Message.regConfirmFailedInvalid;
return Message.get('regConfirmFailedInvalid');
}

if (DateUtil.diff(new Date(info.date), new Date()) > 24) {
return Message.regConfirmFailedExpired;
return Message.get('regConfirmFailedExpired');
}

UserService.active(user.id);

ctx.body = Message.regConfirmSuccess;
ctx.body = Message.get('regConfirmSuccess');
ctx.redirect(Setting.instance.appHost);
}

Expand Down
81 changes: 81 additions & 0 deletions api/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"userEmailRepeat": "email is taken",
"userEmailFormatError": "email format error",
"userPasswordFormatError": "password format error",
"userNameFormatError": "name format error",
"userCreateSuccess": "create user success",
"userCreateFailed": "create user failed",
"userCheckFailed": "email or password error",
"accountNotActive": "account is not active, please active it in your email",
"regSuccess": "register success, please login",
"regSuccessNeedConfirm": "register success, please active your account in your email",
"userLogout": "logout success",
"userLoginSuccess": "login success",
"userNotExist": "user does not exist",
"userOldPwdIncorrect": "old password is incorrect",
"userChangePwdSuccess": "change password success",
"findPwdSuccess": "a new password have send to your mail",
"regConfirmFailedUserNotExist": "check failed, user does not exist",
"regConfirmFailedUserConfirmed": "user was confirmed",
"regConfirmFailedExpired": "verification url was expired",
"regConfirmFailedInvalid": "verification url was invalid",
"regConfirmSuccess": "account is activated, you can use it to login now",

"inviterNotExist": "inviter does not exist",
"emailsAtLeastOne": "at least one email",

"envCreateFailed": "create environment failed",
"envCreateSuccess": "create environment success",
"envUpdateSuccess": "update environment success",
"envDeleteSuccess": "delete environment success",
"envNotExist": "environment does not exist",

"projectSaveSuccess": "project save success",
"projectUpdateSuccess": "project update success",
"projectQuitSuccess": "quit project success",
"projectNotExist": "project does not exist",
"projectDisbandNeedOwner": "only project owner can disband this project",
"projectDisbandSuccess": "disband project success",
"projectDeleteSuccess": "delete project success",
"emailsAllInProject": "emails are all in this project already",
"alreadyInProject": "already in this project",
"joinProjectSuccess": "join project success",
"rejectProjectSuccess": "reject invite success",
"updateLocalhostMappingSuccess": "update localhost mapping success",
"createLocalhostMappingSuccess": "create localhost mapping success",
"updateGlobalFuncSuccess": "update global function success",
"deleteProjectFileSuccess": "delete project file success",

"collectionCreateFailed": "create collection failed",
"collectionCreateSuccess": "create collection success",
"collectionUpdateSuccess": "update collection success",
"collectionNotExist": "collection does not exist",
"collectionDeleteSuccess": "collection delete success",

"recordCreateFailed": "create record failed",
"recordCreateFailedOnName": "record name is incorrect",
"recordSortSuccess": "sort records success",
"recordSaveSuccess": "record save success",
"recordDeleteSuccess": "record delete success",

"scheduleCreateSuccess": "create schedule success",
"scheduleCreateFailed": "create schedule failed",
"scheduleUpdateSuccess": "update schedule success",
"scheduleDeleteSuccess": "delete schedule success",
"scheduleNotExist": "schedule id does not exist",

"stressCreateSuccess": "create stress test success",
"stressCreateFailed": "create stress test failed",
"stressUpdateSuccess": "update stress test success",
"stressDeleteSuccess": "delete stress test success",
"stressNotExist": "stress test case does not exist",
"stressNoRecords": "stress test case does not have any valid request",

"apiNotExist": "this api does not exist",

"sessionInvalid": "session is invalid",

"tokenInvalid": "token is invalid",

"importPostmanSuccess": "import postman data success"
}
Loading

0 comments on commit 09f210c

Please sign in to comment.