package com.sky.ioc.controller.system;

import com.sky.ioc.entity.domain.system.Users;
import com.sky.ioc.entity.params.system.LoginParam;
import com.sky.ioc.service.system.UserService;
import com.sky.ioc.tool.Pbkdf2Sha256Digest;
import com.sky.ioc.tool.ReturnMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "系统设置--用户")
@Slf4j
@RestController
@RequestMapping("/system_user")
public class UserController {

    @Autowired
    UserService userService;
    @ApiOperation("更新常用菜单")
    @PostMapping("saveCommonMenus")
    public ReturnMsg saveCommonMenus(@RequestParam(value = "userID")  long userID,@RequestParam(value = "menuIDs") String menuIDs){
        return userService.updateCommonMenusByUserIdAndMenuId(userID,menuIDs);
    }

    @ApiOperation("修改密码")
    @PostMapping("updatePassword")
    public ReturnMsg updatePassword(@RequestParam(value = "userID")  long userID,
                                    @RequestParam(value = "newpwd") String newpwd,
                                    @RequestParam(value = "oldpwd") String oldpwd){
        return userService.updatePassword(userID,oldpwd,newpwd);
    }


    @ApiOperation("系统登录")
    @PostMapping("/login")
    public ReturnMsg login(@RequestBody LoginParam loginParam) {
        return userService.login(loginParam.getUsername(), loginParam.getPassword());
    }

    @ApiOperation("token 校验")
    @PostMapping("/validate")
    public ReturnMsg validate() {
        return userService.validate();
    }

    @ApiOperation("注销登录")
    @PostMapping("/logout")
    public ReturnMsg logout() {
        return userService.logout();
    }

    @ApiOperation("系统登录--手机号登录")
    @PostMapping("/phonelogin")
    public ReturnMsg phoneLogin(@RequestBody LoginParam loginParam) {
        return userService.phoneLogin(loginParam.getPhone(), loginParam.getCode());
    }


    public static void main(String[] args) {
        String pwd = "135246";
        System.out.println(Pbkdf2Sha256Digest.encode(pwd));
    }

}
