org.springframework.web.bind.annotation.SessionAttribute Java Examples

The following examples show how to use org.springframework.web.bind.annotation.SessionAttribute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
        		Optional.ofNullable(accountService.accountByNameEmail(form.getName(), form.getEmail()).getContent());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        accountService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #2
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           userService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        userService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #3
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           userService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        userService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #4
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
        		Optional.ofNullable(accountService.accountByNameEmail(form.getName(), form.getEmail()).getContent());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        accountService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #5
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           accountService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        accountService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #6
Source File: RegisterController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 发送绑定邮箱验证码
 *
 * @param email
 * @param user
 * @return
 */
@RequestMapping("/bind/email/code")
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public MessageResult sendBindEmail(String email, @SessionAttribute(SESSION_MEMBER) AuthMember user) {
    Assert.isTrue(ValidateUtil.isEmail(email), localeMessageSourceService.getMessage("WRONG_EMAIL"));
    Member member = memberService.findOne(user.getId());
    Assert.isNull(member.getEmail(), localeMessageSourceService.getMessage("BIND_EMAIL_REPEAT"));
    Assert.isTrue(!memberService.emailIsExist(email), localeMessageSourceService.getMessage("EMAIL_ALREADY_BOUND"));
    String code = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    ValueOperations valueOperations = redisTemplate.opsForValue();
    if (valueOperations.get(EMAIL_BIND_CODE_PREFIX + email) != null) {
        return error(localeMessageSourceService.getMessage("EMAIL_ALREADY_SEND"));
    }
    try {
        sentEmailCode(valueOperations, email, code);
    } catch (Exception e) {
        e.printStackTrace();
        return error(localeMessageSourceService.getMessage("SEND_FAILED"));
    }
    return success(localeMessageSourceService.getMessage("SENT_SUCCESS_TEN"));
}
 
Example #7
Source File: RequestMappingHandlerAdapterIntegrationTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
String handleInInterface(
@CookieValue("cookie") int cookieV,
@PathVariable("pathvar") String pathvarV,
@RequestHeader("header") String headerV,
@RequestHeader(defaultValue = "#{systemProperties.systemHeader}") String systemHeader,
@RequestHeader Map<String, Object> headerMap,
@RequestParam("dateParam") Date dateParam,
@RequestParam Map<String, Object> paramMap,
String paramByConvention,
@Value("#{request.contextPath}") String value,
@ModelAttribute("modelAttr") @Valid TestBean modelAttr,
Errors errors,
TestBean modelAttrByConvention,
Color customArg,
HttpServletRequest request,
HttpServletResponse response,
@SessionAttribute TestBean sessionAttribute,
@RequestAttribute TestBean requestAttribute,
User user,
@ModelAttribute OtherUser otherUser,
Model model,
UriComponentsBuilder builder);
 
Example #8
Source File: GoogleVerificationController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 验证google
 * @author shenzucai
 * @time 2018.04.09 11:36
 * @param user
 * @param codes
 * @return true
 */

@RequestMapping(value = "/yzgoogle",method = RequestMethod.GET)
public MessageResult yzgoogle(@SessionAttribute(SESSION_MEMBER) AuthMember user, String codes) {
    // enter the code shown on device. Edit this and run it fast before the
    // code expires!
    long code = Long.parseLong(codes);
    Member member = memberService.findOne(user.getId());
    long t = System.currentTimeMillis();
    GoogleAuthenticatorUtil ga = new GoogleAuthenticatorUtil();
    //  ga.setWindowSize(0); // should give 5 * 30 seconds of grace...
    boolean r = ga.check_code(member.getGoogleKey(), code, t);
    System.out.println("rrrr="+r);
    if(!r){
        return MessageResult.error("验证失败");
    }
    else{
        return MessageResult.success("验证通过");
    }
}
 
Example #9
Source File: GoogleVerificationController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 绑定google
 * @author shenzucai
 * @time 2018.04.09 15:19
 * @param codes
 * @param user
 * @return true
 */
@RequestMapping(value = "/googleAuth" ,method = RequestMethod.POST)
public MessageResult googleAuth(String codes, @SessionAttribute(SESSION_MEMBER) AuthMember user,String secret) {

    Member member = memberService.findOne(user.getId());
    long code = Long.parseLong(codes);
    long t = System.currentTimeMillis();
    GoogleAuthenticatorUtil ga = new GoogleAuthenticatorUtil();
    boolean r = ga.check_code(secret, code, t);
    if(!r){
        return MessageResult.error("验证失败");
    }else{
        member.setGoogleState(1);
        member.setGoogleKey(secret);
        member.setGoogleDate(new Date());
        Member result = memberService.save(member);
        if(result != null){
            return MessageResult.success("绑定成功");
        }else{
            return MessageResult.error("绑定失败");
        }
    }
}
 
Example #10
Source File: FavorController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 添加自选
 * @param member
 * @param symbol
 * @return
 */
@RequestMapping("add")
public MessageResult addFavor(@SessionAttribute(SESSION_MEMBER) AuthMember member, String symbol){
    if(StringUtils.isEmpty(symbol)){
        return MessageResult.error("symbol cannot be empty");
    }
    FavorSymbol favorSymbol = favorSymbolService.findByMemberIdAndSymbol(member.getId(),symbol);
    if(favorSymbol != null){
        return MessageResult.error("symbol already favored");
    }
    FavorSymbol favor =  favorSymbolService.add(member.getId(),symbol);
    if(favor!= null){
        return MessageResult.success("success");
    }
    return MessageResult.error("error");
}
 
Example #11
Source File: MemberController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("new_message")
protected String newMessage(
        @RequestParam String blabla, 
        @SessionAttribute("login") String username, 
        Model model)  {
    
    if(blabla.length() == 0) {
        return REDIRECT_MEMBER_PATH;
    }        
   
    if(blabla.length() <= 140) {
        userService.addMessage(username, blabla);
        return REDIRECT_MEMBER_PATH;
    }
    else {
        model.addAttribute("messages", userService.messages(username));
        return MEMBER_PATH;
    }
}
 
Example #12
Source File: PromotionController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 只查询推荐奖励
 *
 * @param member
 * @return
 */
@RequestMapping(value = "/reward/record")
public MessageResult rewardRecord2(@SessionAttribute(SESSION_MEMBER) AuthMember member, @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
    Page<RewardRecord> pageList = rewardRecordService.queryRewardPromotionPage(pageNo, pageSize, memberService.findOne(member.getId()));
    MessageResult result = MessageResult.success();
    List<RewardRecord> list = pageList.getContent();
    result.setData(list.stream().map(x ->
            PromotionRewardRecord.builder().amount(x.getAmount())
                    .createTime(x.getCreateTime())
                    .remark(x.getRemark())
                    .symbol(x.getCoin().getUnit())
                    .build()
    ).collect(Collectors.toList()));

    result.setTotalPage(pageList.getTotalPages() + "");
    result.setTotalElement(pageList.getTotalElements() + "");
    return result;
}
 
Example #13
Source File: MemberController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@PostMapping("sign-in")
public MessageResult signIn(@SessionAttribute(SESSION_MEMBER) AuthMember user) {
    //校验 签到活动 币种 会员 会员钱包
    Assert.notNull(user, "The login timeout!");

    Sign sign = signService.fetchUnderway();
    Assert.notNull(sign, "The check-in activity is over!");

    Coin coin = sign.getCoin();
    Assert.isTrue(coin.getStatus() == CommonStatus.NORMAL, "coin disabled!");

    Member member = memberService.findOne(user.getId());
    Assert.notNull(member, "validate member id!");
    Assert.isTrue(member.getSignInAbility() == true, "Have already signed in!");

    MemberWallet memberWallet = walletService.findByCoinAndMember(coin, member);
    Assert.notNull(memberWallet, "Member wallet does not exist!");
    Assert.isTrue(memberWallet.getIsLock() == BooleanEnum.IS_FALSE, "Wallet locked!");

    //签到事件
    memberService.signInIncident(member, memberWallet, sign);

    return success();
}
 
Example #14
Source File: MemberController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@PostMapping("sign-in")
public MessageResult signIn(@SessionAttribute(SESSION_MEMBER) AuthMember user) {
    //校验 签到活动 币种 会员 会员钱包
    Assert.notNull(user, "The login timeout!");

    Sign sign = signService.fetchUnderway();
    Assert.notNull(sign, "The check-in activity is over!");

    Coin coin = sign.getCoin();
    Assert.isTrue(coin.getStatus() == CommonStatus.NORMAL, "coin disabled!");

    Member member = memberService.findOne(user.getId());
    Assert.notNull(member, "validate member id!");
    Assert.isTrue(member.getSignInAbility() == true, "Have already signed in!");

    MemberWallet memberWallet = walletService.findByCoinAndMember(coin, member);
    Assert.notNull(memberWallet, "Member wallet does not exist!");
    Assert.isTrue(memberWallet.getIsLock() == BooleanEnum.IS_FALSE, "Wallet locked!");

    //签到事件
    memberService.signInIncident(member, memberWallet, sign);

    return success();
}
 
Example #15
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           accountService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        accountService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #16
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           userService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        userService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #17
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
        		Optional.ofNullable(accountService.accountByNameEmail(form.getName(), form.getEmail()).getContent());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        accountService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #18
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
        		Optional.ofNullable(accountService.accountByNameEmail(form.getName(), form.getEmail()).getContent());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        accountService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #19
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public Mono<String> resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return Mono.just(REDIRECT_INDEX_PATH);
    }
    
    return toList(bindingResult)
          .flatMap(errors -> {
          	if(!errors.isEmpty()) {
                  model.addAttribute("errors", errors);
                  model.addAttribute("name", form.getName());
                  model.addAttribute("email", form.getEmail());
                  return Mono.just(RESET_PASSWORD_FORM_PATH);
              } 
              return userService
          		         .resetPassword(form.getName(), form.getPassword())
                           .then(Mono.just(RESET_PASSWORD_SUCCESS_PATH)); 
          });
}
 
Example #20
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           userService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        userService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #21
Source File: BusinessAuthController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
@RequiresPermissions("business:auth:deposit:create")
@PostMapping("create")
public MessageResult create(@SessionAttribute(SysConstant.SESSION_ADMIN) Admin admin,
                            @RequestParam("amount") Double amount,
                            @RequestParam("coinUnit") String coinUnit) {
    Coin coin = coinService.findByUnit(coinUnit);
    if (coin == null) {
        return error("validate coinUnit");
    }
    BusinessAuthDeposit businessAuthDeposit = new BusinessAuthDeposit();
    businessAuthDeposit.setAmount(new BigDecimal(amount));
    businessAuthDeposit.setCoin(coin);
    businessAuthDeposit.setCreateTime(new Date());
    businessAuthDeposit.setAdmin(admin);
    businessAuthDeposit.setStatus(CommonStatus.NORMAL);
    businessAuthDepositService.save(businessAuthDeposit);
    return success();
}
 
Example #22
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           userService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        userService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}
 
Example #23
Source File: AssetController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 查询所有记录
 *
 * @param member
 * @param pageNo
 * @param pageSize
 * @return
 */
@RequestMapping("transaction/all")
public MessageResult findTransaction(@SessionAttribute(SESSION_MEMBER) AuthMember member, HttpServletRequest request, int pageNo, int pageSize,
                                     @RequestParam(value = "startTime",required = false)  String startTime,
                                     @RequestParam(value = "endTime",required = false)  String endTime,
                                     @RequestParam(value = "symbol",required = false)  String symbol,
                                     @RequestParam(value = "type",required = false)  String type) throws ParseException {
    MessageResult mr = new MessageResult();
    TransactionType transactionType = null;
    if (StringUtils.isNotEmpty(type)) {
        transactionType = TransactionType.valueOfOrdinal(Convert.strToInt(type, 0));
    }
    mr.setCode(0);
    mr.setMessage("success");
    mr.setData(transactionService.queryByMember(member.getId(), pageNo, pageSize, transactionType, startTime, endTime,symbol));
    return mr;
}
 
Example #24
Source File: MemberController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("new_message")
protected String newMessage(
        @RequestParam String blabla, 
        @SessionAttribute("login") String username, 
        Model model)  {
    
    if(blabla.length() == 0) {
        return REDIRECT_MEMBER_PATH;
    }        
   
    if(blabla.length() <= 140) {
        userService.addMessage(username, blabla);
        return REDIRECT_MEMBER_PATH;
    }
    else {
        model.addAttribute("messages", userService.messages(username));
        return MEMBER_PATH;
    }
}
 
Example #25
Source File: GoogleVerificationController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 验证google
 * @author shenzucai
 * @time 2018.04.09 11:36
 * @param user
 * @param codes
 * @return true
 */

@RequestMapping(value = "/yzgoogle",method = RequestMethod.GET)
public MessageResult yzgoogle(@SessionAttribute(SESSION_MEMBER) AuthMember user, String codes) {
    // enter the code shown on device. Edit this and run it fast before the
    // code expires!
    long code = Long.parseLong(codes);
    Member member = memberService.findOne(user.getId());
    long t = System.currentTimeMillis();
    GoogleAuthenticatorUtil ga = new GoogleAuthenticatorUtil();
    //  ga.setWindowSize(0); // should give 5 * 30 seconds of grace...
    boolean r = ga.check_code(member.getGoogleKey(), code, t);
    System.out.println("rrrr="+r);
    if(!r){
        return MessageResult.error("验证失败");
    }
    else{
        return MessageResult.success("验证通过");
    }
}
 
Example #26
Source File: AssetController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 用户钱包信息
 *
 * @param member
 * @return
 */
@RequestMapping("wallet")
public MessageResult findWallet(@SessionAttribute(SESSION_MEMBER) AuthMember member) {
    List<MemberWallet> wallets = walletService.findAllByMemberId(member.getId());
    wallets.forEach(wallet -> {
        CoinExchangeFactory.ExchangeRate rate = coinExchangeFactory.get(wallet.getCoin().getUnit());
        if (rate != null) {
            wallet.getCoin().setUsdRate(rate.getUsdRate().doubleValue());
            wallet.getCoin().setCnyRate(rate.getCnyRate().doubleValue());
        } else {
            log.info("unit = {} , rate = null ", wallet.getCoin().getUnit());
        }
    });
    MessageResult mr = MessageResult.success("success");
    mr.setData(wallets);
    return mr;
}
 
Example #27
Source File: RegisterController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 增加提币地址验证码
 *
 * @param user
 * @return
 */
@RequestMapping("/add/address/code")
@ResponseBody
@Transactional(rollbackFor = Exception.class)
public MessageResult sendAddAddress(@SessionAttribute(SESSION_MEMBER) AuthMember user) {
    String code = String.valueOf(GeneratorUtil.getRandomNumber(100000, 999999));
    ValueOperations valueOperations = redisTemplate.opsForValue();
    Member member = memberService.findOne(user.getId());
    String email = member.getEmail();
    if (email == null) {
        return error(localeMessageSourceService.getMessage("NOT_BIND_EMAIL"));
    }
    if (valueOperations.get(ADD_ADDRESS_CODE_PREFIX + email) != null) {
        return error(localeMessageSourceService.getMessage("EMAIL_ALREADY_SEND"));
    }
    try {
        sentEmailAddCode(valueOperations, email, code);
    } catch (Exception e) {
        e.printStackTrace();
        return error(localeMessageSourceService.getMessage("SEND_FAILED"));
    }
    return success(localeMessageSourceService.getMessage("SENT_SUCCESS_TEN"));
}
 
Example #28
Source File: MemberController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("new_message")
protected String newMessage(
        @RequestParam String blabla, 
        @SessionAttribute("login") String username, 
        Model model)  {
    
    if(blabla.length() == 0) {
        return REDIRECT_MEMBER_PATH;
    }        
   
    if(blabla.length() <= 140) {
        userService.addMessage(username, blabla);
        return REDIRECT_MEMBER_PATH;
    }
    else {
        model.addAttribute("messages", userService.messages(username));
        return MEMBER_PATH;
    }
}
 
Example #29
Source File: FavorController.java    From ZTuoExchange_framework with MIT License 6 votes vote down vote up
/**
 * 添加自选
 * @param member
 * @param symbol
 * @return
 */
@RequestMapping("add")
public MessageResult addFavor(@SessionAttribute(SESSION_MEMBER) AuthMember member, String symbol){
    if(StringUtils.isEmpty(symbol)){
        return MessageResult.error("symbol cannot be empty");
    }
    FavorSymbol favorSymbol = favorSymbolService.findByMemberIdAndSymbol(member.getId(),symbol);
    if(favorSymbol != null){
        return MessageResult.error("symbol already favored");
    }
    FavorSymbol favor =  favorSymbolService.add(member.getId(),symbol);
    if(favor!= null){
        return MessageResult.success("success");
    }
    return MessageResult.error("error");
}
 
Example #30
Source File: AccountController.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostMapping("reset_password")
public String resetPassword( 
        @Valid ResetPasswordForm form,
        BindingResult bindingResult,
        @SessionAttribute(name = "token") String storedToken,
        Model model) {
    
    if(storedToken == null || !storedToken.equals(form.getToken())) {
        return REDIRECT_INDEX_PATH;
    }
    
    List<String> errors = toList(bindingResult);
    
    if(!errors.isEmpty()) {
        Optional<Account> optionalAcct =
           userService.accountByNameEmail(form.getName(), form.getEmail());
        model.addAttribute("errors", errors);
        model.addAttribute("acct", optionalAcct.get());
        return RESET_PASSWORD_FORM_PATH;
    } else {
        userService.resetPassword(form.getName(), form.getPassword());
        return RESET_PASSWORD_SUCCESS_PATH;
    }    
}