package com.ruoyi.thirduser.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.thirduser.service.ThirdUserloginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
@Slf4j
@RestController
public class LoginController {

    @Autowired
    private ThirdUserloginService thirdUserloginService;

    @PostMapping("/mailLogin")
    @Anonymous
    public AjaxResult mailLogin(@RequestBody LoginBody loginBody){
        String token = thirdUserloginService.mailLogin(loginBody.getUsername(), loginBody.getPassword());
        AjaxResult ajax = AjaxResult.success();
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }
    @PostMapping("/mailRegister")
    @Anonymous
    public AjaxResult registerByMail(@RequestBody(required=false) RegisterBody loginBody){
        log.info(String.valueOf(loginBody));
        String s = thirdUserloginService.mailRegister(loginBody.getUsername(), loginBody.getPassword());
        AjaxResult ajax = AjaxResult.success(s);
        return ajax;
    }
}
