/** * Activate a new user * * <b>Request Type</b>: POST<br/><br/> * <b>Request Endpoint</b>:http://{server-domain}/site/update-info<br/><br/> * <b>Content-type</b>: application/json<br/><br/> * <b>Summary</b>: This api is used for a user to activate account * <br/><br/> * * <b>Request Params</b>:<br/> * name: string, the user name, required<br/> * password: string, the user password, required<br/> * id: string, the user id, required<br/> * avatar: string, the user avatar, required<br/> * code: string, the user validation code, required<br/> * <br/><br/> * * <b>Response Params:</b><br/> * ack: integer, mark the create result, 0 means create successfully, 1 means create fail<br/> * data: array, json array to describe user id<br/> * <br/><br/> * * <b>Request Example:</b><br/> * <pre> * { * "name" : "sarazhang", * "password" : "45345345gdfgdf", * "id" : "643hfjht567", * "avatar" : "http://www.baidu.com/1.jpg", * "code" : "543gfdg45745sd", * * } * </pre> * <br/><br/> * * <b>Response Example</b>:<br/> * <pre> * { * 'ack' : 1, * 'data': {"id": "5345gdfg45745"} * } * </pre> */ public function actionUpdateInfo() { $data = $this->getParams(); if (empty($data['password']) || empty($data['name']) || empty($data['id']) || $data['password'] === md5('')) { throw new BadRequestHttpException(Yii::t('common', 'parameters_missing')); } $code = empty($data['code']) ? '' : $data['code']; $type = empty($data['type']) ? '' : $data['type']; $result = Validation::validateCode($code, false); if ($result == Validation::LINK_INVALID) { throw new GoneHttpException(Yii::t('common', 'link_invalid')); } else { if ($result == Validation::LINK_EXPIRED) { throw new GoneHttpException(Yii::t('common', 'link_invalid')); } } $salt = StringUtil::rndString(6); $password = User::encryptPassword($data['password'], $salt); $name = $data['name']; $avatar = $data['avatar']; $id = $data['id']; if (!empty($type) && $type == self::ACCOUNT_INVITATION) { $user = User::findOne(['_id' => $id]); $accountId = $user->accountId; if (empty(User::getByName($accountId, $name))) { $user->isActivated = User::ACTIVATED; $user->salt = $salt; $user->language = Yii::$app->language; $user->password = $password; $user->name = $name; $user->avatar = $avatar; $flag = $user->save(); } else { throw new InvalidParameterException(['name' => Yii::t('common', 'name_exist')]); } } else { if (!empty($type) && $type == self::HELPDESK_INVITATION) { $helpDesk = HelpDesk::findOne(['_id' => $id]); $accountId = $helpDesk->accountId; if (empty(HelpDesk::getByName($accountId, $name))) { $helpDesk->isActivated = User::ACTIVATED; $helpDesk->language = Yii::$app->language; $helpDesk->salt = $salt; $helpDesk->password = $password; $helpDesk->name = $name; $helpDesk->avatar = $avatar; $flag = $helpDesk->save(); } else { throw new InvalidParameterException(['name' => Yii::t('common', 'name_exist')]); } } } if ($flag) { Validation::deleteAll(['code' => $code]); return ['id' => $id, 'type' => $type]; } throw new ServerErrorHttpException('activate fail'); }