UsersController.java 22.1 KB
Newer Older
L
ligang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Q
qiaozhanwei 已提交
17
package org.apache.dolphinscheduler.api.controller;
L
ligang 已提交
18 19


Q
qiaozhanwei 已提交
20
import org.apache.dolphinscheduler.api.enums.Status;
21
import org.apache.dolphinscheduler.api.exceptions.ApiException;
Q
qiaozhanwei 已提交
22 23
import org.apache.dolphinscheduler.api.service.UsersService;
import org.apache.dolphinscheduler.api.utils.Result;
24
import org.apache.dolphinscheduler.common.Constants;
Q
qiaozhanwei 已提交
25 26
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User;
L
lidongdai 已提交
27 28 29 30
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
L
ligang 已提交
31 32 33 34 35
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
L
lidongdai 已提交
36
import springfox.documentation.annotations.ApiIgnore;
L
ligang 已提交
37

38 39
import static org.apache.dolphinscheduler.api.enums.Status.*;

S
sky 已提交
40 41 42 43
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

L
ligang 已提交
44 45 46 47

/**
 * user controller
 */
48
@Api(tags = "USERS_TAG", position = 14)
L
ligang 已提交
49 50
@RestController
@RequestMapping("/users")
51
public class UsersController extends BaseController {
L
ligang 已提交
52 53 54 55 56 57 58 59

    private static final Logger logger = LoggerFactory.getLogger(UsersController.class);

    @Autowired
    private UsersService usersService;

    /**
     * create user
60 61 62
     *
     * @param loginUser    login user
     * @param userName     user name
B
bao liang 已提交
63
     * @param userPassword user password
64 65 66 67
     * @param email        email
     * @param tenantId     tenant id
     * @param phone        phone
     * @param queue        queue
B
bao liang 已提交
68
     * @return create result code
L
ligang 已提交
69
     */
70
    @ApiOperation(value = "createUser", notes = "CREATE_USER_NOTES")
L
lidongdai 已提交
71
    @ApiImplicitParams({
72 73
            @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"),
            @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"),
L
lidongdai 已提交
74 75 76
            @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"),
R
Rubik-W 已提交
77 78
            @ApiImplicitParam(name = "phone", value = "PHONE", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "state", value = "STATE", dataType = "Int", example = "1")
L
lidongdai 已提交
79
    })
L
ligang 已提交
80 81
    @PostMapping(value = "/create")
    @ResponseStatus(HttpStatus.CREATED)
82
    @ApiException(CREATE_USER_ERROR)
L
lidongdai 已提交
83
    public Result createUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
84 85 86 87 88
                             @RequestParam(value = "userName") String userName,
                             @RequestParam(value = "userPassword") String userPassword,
                             @RequestParam(value = "tenantId") int tenantId,
                             @RequestParam(value = "queue", required = false, defaultValue = "") String queue,
                             @RequestParam(value = "email") String email,
R
Rubik-W 已提交
89 90 91 92 93
                             @RequestParam(value = "phone", required = false) String phone,
                             @RequestParam(value = "state", required = false) int state) throws Exception {
        logger.info("login user {}, create user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}, state: {}",
                loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone, queue, state);
        Map<String, Object> result = usersService.createUser(loginUser, userName, userPassword, email, tenantId, phone, queue, state);
94
        return returnDataList(result);
L
ligang 已提交
95 96 97 98 99
    }

    /**
     * query user list paging
     *
B
bao liang 已提交
100
     * @param loginUser login user
101
     * @param pageNo    page number
B
bao liang 已提交
102
     * @param searchVal search avlue
103
     * @param pageSize  page size
B
bao liang 已提交
104
     * @return user list page
L
ligang 已提交
105
     */
106
    @ApiOperation(value = "queryUserList", notes = "QUERY_USER_LIST_NOTES")
L
lidongdai 已提交
107
    @ApiImplicitParams({
108 109 110
            @ApiImplicitParam(name = "pageNo", value = "PAGE_NO", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", type = "String"),
            @ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", type = "String")
L
lidongdai 已提交
111
    })
112
    @GetMapping(value = "/list-paging")
L
ligang 已提交
113
    @ResponseStatus(HttpStatus.OK)
114
    @ApiException(QUERY_USER_LIST_PAGING_ERROR)
L
lidongdai 已提交
115
    public Result queryUserList(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
116 117
                                @RequestParam("pageNo") Integer pageNo,
                                @RequestParam(value = "searchVal", required = false) String searchVal,
118
                                @RequestParam("pageSize") Integer pageSize) {
L
ligang 已提交
119
        logger.info("login user {}, list user paging, pageNo: {}, searchVal: {}, pageSize: {}",
120 121 122
                loginUser.getUserName(), pageNo, searchVal, pageSize);
        Map<String, Object> result = checkPageParams(pageNo, pageSize);
        if (result.get(Constants.STATUS) != Status.SUCCESS) {
L
ligang 已提交
123 124
            return returnDataListPaging(result);
        }
125 126 127
        searchVal = ParameterUtils.handleEscapes(searchVal);
        result = usersService.queryUserList(loginUser, searchVal, pageNo, pageSize);
        return returnDataListPaging(result);
L
ligang 已提交
128 129 130 131
    }


    /**
L
lidongdai 已提交
132
     * update user
L
ligang 已提交
133
     *
134 135 136
     * @param loginUser    login user
     * @param id           user id
     * @param userName     user name
B
bao liang 已提交
137
     * @param userPassword user password
138 139 140 141
     * @param email        email
     * @param tenantId     tennat id
     * @param phone        phone
     * @param queue        queue
B
bao liang 已提交
142
     * @return update result code
L
ligang 已提交
143
     */
144
    @ApiOperation(value = "updateUser", notes = "UPDATE_USER_NOTES")
L
lidongdai 已提交
145
    @ApiImplicitParams({
146 147 148
            @ApiImplicitParam(name = "id", value = "USER_ID", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"),
            @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"),
L
lidongdai 已提交
149 150 151
            @ApiImplicitParam(name = "tenantId", value = "TENANT_ID", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "queue", value = "QUEUE", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "email", value = "EMAIL", dataType = "Int", example = "100"),
R
Rubik-W 已提交
152 153
            @ApiImplicitParam(name = "phone", value = "PHONE", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "state", value = "STATE", dataType = "Int", example = "1")
L
lidongdai 已提交
154
    })
L
ligang 已提交
155 156
    @PostMapping(value = "/update")
    @ResponseStatus(HttpStatus.OK)
157
    @ApiException(UPDATE_USER_ERROR)
L
lidongdai 已提交
158
    public Result updateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
159 160 161 162 163 164
                             @RequestParam(value = "id") int id,
                             @RequestParam(value = "userName") String userName,
                             @RequestParam(value = "userPassword") String userPassword,
                             @RequestParam(value = "queue", required = false, defaultValue = "") String queue,
                             @RequestParam(value = "email") String email,
                             @RequestParam(value = "tenantId") int tenantId,
R
Rubik-W 已提交
165 166 167 168 169
                             @RequestParam(value = "phone", required = false) String phone,
                             @RequestParam(value = "state", required = false) int state) throws Exception {
        logger.info("login user {}, updateProcessInstance user, userName: {}, email: {}, tenantId: {}, userPassword: {}, phone: {}, user queue: {}, state: {}",
                loginUser.getUserName(), userName, email, tenantId, Constants.PASSWORD_DEFAULT, phone, queue, state);
        Map<String, Object> result = usersService.updateUser(id, userName, userPassword, email, tenantId, phone, queue, state);
170
        return returnDataList(result);
L
ligang 已提交
171 172 173 174
    }

    /**
     * delete user by id
175
     *
B
bao liang 已提交
176
     * @param loginUser login user
177
     * @param id        user id
B
bao liang 已提交
178
     * @return delete result code
L
ligang 已提交
179
     */
180
    @ApiOperation(value = "delUserById", notes = "DELETE_USER_BY_ID_NOTES")
L
lidongdai 已提交
181
    @ApiImplicitParams({
182
            @ApiImplicitParam(name = "id", value = "USER_ID", dataType = "Int", example = "100")
L
lidongdai 已提交
183
    })
L
ligang 已提交
184 185
    @PostMapping(value = "/delete")
    @ResponseStatus(HttpStatus.OK)
186
    @ApiException(DELETE_USER_BY_ID_ERROR)
L
lidongdai 已提交
187
    public Result delUserById(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
188
                              @RequestParam(value = "id") int id) throws Exception {
L
ligang 已提交
189
        logger.info("login user {}, delete user, userId: {},", loginUser.getUserName(), id);
190 191
        Map<String, Object> result = usersService.deleteUserById(loginUser, id);
        return returnDataList(result);
L
ligang 已提交
192 193 194 195 196
    }

    /**
     * grant project
     *
197 198
     * @param loginUser  login user
     * @param userId     user id
B
bao liang 已提交
199 200
     * @param projectIds project id array
     * @return grant result code
L
ligang 已提交
201
     */
202
    @ApiOperation(value = "grantProject", notes = "GRANT_PROJECT_NOTES")
L
lidongdai 已提交
203
    @ApiImplicitParams({
204 205
            @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "projectIds", value = "PROJECT_IDS", type = "String")
L
lidongdai 已提交
206
    })
L
ligang 已提交
207 208
    @PostMapping(value = "/grant-project")
    @ResponseStatus(HttpStatus.OK)
209
    @ApiException(GRANT_PROJECT_ERROR)
L
lidongdai 已提交
210
    public Result grantProject(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
211 212 213 214 215
                               @RequestParam(value = "userId") int userId,
                               @RequestParam(value = "projectIds") String projectIds) {
        logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, projectIds);
        Map<String, Object> result = usersService.grantProject(loginUser, userId, projectIds);
        return returnDataList(result);
L
ligang 已提交
216 217 218 219 220
    }

    /**
     * grant resource
     *
221 222
     * @param loginUser   login user
     * @param userId      user id
B
bao liang 已提交
223 224
     * @param resourceIds resource id array
     * @return grant result code
L
ligang 已提交
225
     */
226
    @ApiOperation(value = "grantResource", notes = "GRANT_RESOURCE_NOTES")
L
lidongdai 已提交
227
    @ApiImplicitParams({
228 229
            @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "resourceIds", value = "RESOURCE_IDS", type = "String")
L
lidongdai 已提交
230
    })
L
ligang 已提交
231 232
    @PostMapping(value = "/grant-file")
    @ResponseStatus(HttpStatus.OK)
233
    @ApiException(GRANT_RESOURCE_ERROR)
L
lidongdai 已提交
234
    public Result grantResource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
235 236 237 238 239
                                @RequestParam(value = "userId") int userId,
                                @RequestParam(value = "resourceIds") String resourceIds) {
        logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, resourceIds);
        Map<String, Object> result = usersService.grantResources(loginUser, userId, resourceIds);
        return returnDataList(result);
L
ligang 已提交
240 241 242 243 244 245
    }


    /**
     * grant udf function
     *
B
bao liang 已提交
246
     * @param loginUser login user
247 248
     * @param userId    user id
     * @param udfIds    udf id array
B
bao liang 已提交
249
     * @return grant result code
L
ligang 已提交
250
     */
251
    @ApiOperation(value = "grantUDFFunc", notes = "GRANT_UDF_FUNC_NOTES")
L
lidongdai 已提交
252
    @ApiImplicitParams({
253 254
            @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "udfIds", value = "UDF_IDS", type = "String")
L
lidongdai 已提交
255
    })
L
ligang 已提交
256 257
    @PostMapping(value = "/grant-udf-func")
    @ResponseStatus(HttpStatus.OK)
258
    @ApiException(GRANT_UDF_FUNCTION_ERROR)
L
lidongdai 已提交
259
    public Result grantUDFFunc(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
260 261 262 263 264
                               @RequestParam(value = "userId") int userId,
                               @RequestParam(value = "udfIds") String udfIds) {
        logger.info("login user {}, grant project, userId: {},resourceIds : {}", loginUser.getUserName(), userId, udfIds);
        Map<String, Object> result = usersService.grantUDFFunction(loginUser, userId, udfIds);
        return returnDataList(result);
L
ligang 已提交
265 266 267 268 269 270
    }


    /**
     * grant datasource
     *
271 272 273
     * @param loginUser     login user
     * @param userId        user id
     * @param datasourceIds data source id array
B
bao liang 已提交
274
     * @return grant result code
L
ligang 已提交
275
     */
276
    @ApiOperation(value = "grantDataSource", notes = "GRANT_DATASOURCE_NOTES")
L
lidongdai 已提交
277
    @ApiImplicitParams({
278 279
            @ApiImplicitParam(name = "userId", value = "USER_ID", dataType = "Int", example = "100"),
            @ApiImplicitParam(name = "datasourceIds", value = "DATASOURCE_IDS", type = "String")
L
lidongdai 已提交
280
    })
L
ligang 已提交
281 282
    @PostMapping(value = "/grant-datasource")
    @ResponseStatus(HttpStatus.OK)
283
    @ApiException(GRANT_DATASOURCE_ERROR)
L
lidongdai 已提交
284
    public Result grantDataSource(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
285 286 287 288 289
                                  @RequestParam(value = "userId") int userId,
                                  @RequestParam(value = "datasourceIds") String datasourceIds) {
        logger.info("login user {}, grant project, userId: {},projectIds : {}", loginUser.getUserName(), userId, datasourceIds);
        Map<String, Object> result = usersService.grantDataSource(loginUser, userId, datasourceIds);
        return returnDataList(result);
L
ligang 已提交
290 291 292 293 294 295
    }


    /**
     * get user info
     *
B
bao liang 已提交
296 297
     * @param loginUser login user
     * @return user info
L
ligang 已提交
298
     */
299 300
    @ApiOperation(value = "getUserInfo", notes = "GET_USER_INFO_NOTES")
    @GetMapping(value = "/get-user-info")
L
ligang 已提交
301
    @ResponseStatus(HttpStatus.OK)
302 303
    @ApiException(GET_USER_INFO_ERROR)
    public Result getUserInfo(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
304
        logger.info("login user {},get user info", loginUser.getUserName());
305 306
        Map<String, Object> result = usersService.getUserInfo(loginUser);
        return returnDataList(result);
L
ligang 已提交
307 308 309 310 311
    }

    /**
     * user list no paging
     *
B
bao liang 已提交
312 313
     * @param loginUser login user
     * @return user list
L
ligang 已提交
314
     */
315 316
    @ApiOperation(value = "listUser", notes = "LIST_USER_NOTES")
    @GetMapping(value = "/list")
L
ligang 已提交
317
    @ResponseStatus(HttpStatus.OK)
318 319
    @ApiException(USER_LIST_ERROR)
    public Result listUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
320
        logger.info("login user {}, user list", loginUser.getUserName());
321 322
        Map<String, Object> result = usersService.queryAllGeneralUsers(loginUser);
        return returnDataList(result);
Q
qiaozhanwei 已提交
323 324 325 326 327 328
    }


    /**
     * user list no paging
     *
B
bao liang 已提交
329 330
     * @param loginUser login user
     * @return user list
Q
qiaozhanwei 已提交
331
     */
332
    @GetMapping(value = "/list-all")
Q
qiaozhanwei 已提交
333
    @ResponseStatus(HttpStatus.OK)
334 335
    @ApiException(USER_LIST_ERROR)
    public Result listAll(@RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
336
        logger.info("login user {}, user list", loginUser.getUserName());
337 338
        Map<String, Object> result = usersService.queryUserList(loginUser);
        return returnDataList(result);
L
ligang 已提交
339 340
    }

Q
qiaozhanwei 已提交
341

L
ligang 已提交
342 343 344
    /**
     * verify username
     *
B
bao liang 已提交
345
     * @param loginUser login user
346
     * @param userName  user name
B
bao liang 已提交
347
     * @return true if user name not exists, otherwise return false
L
ligang 已提交
348
     */
349
    @ApiOperation(value = "verifyUserName", notes = "VERIFY_USER_NAME_NOTES")
L
lidongdai 已提交
350
    @ApiImplicitParams({
351
            @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String")
L
lidongdai 已提交
352
    })
L
ligang 已提交
353 354
    @GetMapping(value = "/verify-user-name")
    @ResponseStatus(HttpStatus.OK)
355
    @ApiException(VERIFY_USERNAME_ERROR)
L
lidongdai 已提交
356
    public Result verifyUserName(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
357
                                 @RequestParam(value = "userName") String userName
L
ligang 已提交
358
    ) {
359 360 361
        logger.info("login user {}, verfiy user name: {}",
                loginUser.getUserName(), userName);
        return usersService.verifyUserName(userName);
L
ligang 已提交
362 363 364 365 366 367
    }


    /**
     * unauthorized user
     *
368
     * @param loginUser    login user
B
bao liang 已提交
369 370
     * @param alertgroupId alert group id
     * @return unauthorize result code
L
ligang 已提交
371
     */
372
    @ApiOperation(value = "unauthorizedUser", notes = "UNAUTHORIZED_USER_NOTES")
L
lidongdai 已提交
373
    @ApiImplicitParams({
374
            @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", type = "String")
L
lidongdai 已提交
375
    })
L
ligang 已提交
376 377
    @GetMapping(value = "/unauth-user")
    @ResponseStatus(HttpStatus.OK)
378
    @ApiException(UNAUTHORIZED_USER_ERROR)
L
lidongdai 已提交
379
    public Result unauthorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
380
                                   @RequestParam("alertgroupId") Integer alertgroupId) {
381 382 383 384
        logger.info("unauthorized user, login user:{}, alert group id:{}",
                loginUser.getUserName(), alertgroupId);
        Map<String, Object> result = usersService.unauthorizedUser(loginUser, alertgroupId);
        return returnDataList(result);
L
ligang 已提交
385 386 387 388 389 390
    }


    /**
     * authorized user
     *
391
     * @param loginUser    login user
B
bao liang 已提交
392 393
     * @param alertgroupId alert group id
     * @return authorized result code
L
ligang 已提交
394
     */
395
    @ApiOperation(value = "authorizedUser", notes = "AUTHORIZED_USER_NOTES")
L
lidongdai 已提交
396
    @ApiImplicitParams({
397
            @ApiImplicitParam(name = "alertgroupId", value = "ALERT_GROUP_ID", type = "String")
L
lidongdai 已提交
398
    })
L
ligang 已提交
399 400
    @GetMapping(value = "/authed-user")
    @ResponseStatus(HttpStatus.OK)
401
    @ApiException(AUTHORIZED_USER_ERROR)
L
lidongdai 已提交
402
    public Result authorizedUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
L
ligang 已提交
403
                                 @RequestParam("alertgroupId") Integer alertgroupId) {
404
        try {
L
ligang 已提交
405 406 407 408
            logger.info("authorized user , login user:{}, alert group id:{}",
                    loginUser.getUserName(), alertgroupId);
            Map<String, Object> result = usersService.authorizedUser(loginUser, alertgroupId);
            return returnDataList(result);
409 410
        } catch (Exception e) {
            logger.error(Status.AUTHORIZED_USER_ERROR.getMsg(), e);
L
ligang 已提交
411 412 413 414
            return error(Status.AUTHORIZED_USER_ERROR.getCode(), Status.AUTHORIZED_USER_ERROR.getMsg());
        }
    }

S
sky 已提交
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
    /**
     * user register
     *
     * @param userName       user name
     * @param userPassword   user password
     * @param repeatPassword repeat password
     * @param email          user email
     */
    @ApiOperation(value="registerUser",notes = "REGISTER_USER_NOTES")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"),
            @ApiImplicitParam(name = "userPassword", value = "USER_PASSWORD", type = "String"),
            @ApiImplicitParam(name = "repeatPassword", value = "REPEAT_PASSWORD", type = "String"),
            @ApiImplicitParam(name = "email", value = "EMAIL", type = "String"),
    })
    @PostMapping("/register")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(CREATE_USER_ERROR)
    public Result<Object> registerUser(@RequestParam(value = "userName") String userName,
                               @RequestParam(value = "userPassword") String userPassword,
                               @RequestParam(value = "repeatPassword") String repeatPassword,
                               @RequestParam(value = "email") String email) throws Exception {
S
sky 已提交
437 438 439 440
        userName = ParameterUtils.handleEscapes(userName);
        userPassword = ParameterUtils.handleEscapes(userPassword);
        repeatPassword = ParameterUtils.handleEscapes(repeatPassword);
        email = ParameterUtils.handleEscapes(email);
S
sky 已提交
441
        logger.info("user self-register, userName: {}, userPassword {}, repeatPassword {}, eamil {}",
S
sky 已提交
442
                userName, Constants.PASSWORD_DEFAULT, Constants.PASSWORD_DEFAULT, email);
S
sky 已提交
443 444 445
        Map<String, Object> result = usersService.registerUser(userName, userPassword, repeatPassword, email);
        return returnDataList(result);
    }
L
ligang 已提交
446

S
sky 已提交
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
    /**
     * user activate
     *
     * @param userName       user name
     */
    @ApiOperation(value="activateUser",notes = "ACTIVATE_USER_NOTES")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userName", value = "USER_NAME", type = "String"),
    })
    @PostMapping("/activate")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(UPDATE_USER_ERROR)
    public Result<Object> activateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                       @RequestParam(value = "userName") String userName) {
        userName = ParameterUtils.handleEscapes(userName);
        logger.info("login user {}, activate user, userName: {}",
                loginUser.getUserName(), userName);
        Map<String, Object> result = usersService.activateUser(loginUser, userName);
        return returnDataList(result);
    }
S
sky 已提交
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486

    /**
     * user batch activate
     *
     * @param  userNames       user names
     */
    @ApiOperation(value = "batchActivateUser",notes = "BATCH_ACTIVATE_USER_NOTES")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userNames", value = "USER_NAMES", type = "String"),
    })
    @PostMapping("/batch/activate")
    @ResponseStatus(HttpStatus.OK)
    @ApiException(UPDATE_USER_ERROR)
    public Result<Object> batchActivateUser(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
                                       @RequestBody List<String> userNames) {
        List<String> formatUserNames = userNames.stream().map(ParameterUtils::handleEscapes).collect(Collectors.toList());
        logger.info(" activate userNames: {}", formatUserNames);
        Map<String, Object> result = usersService.batchActivateUser(loginUser, formatUserNames);
        return returnDataList(result);
    }
L
ligang 已提交
487
}