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

The following examples show how to use org.springframework.web.bind.annotation.SessionAttribute. These examples are extracted from open source projects. 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
@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 2
@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 3
Source Project: ZTuoExchange_framework   Source File: RegisterController.java    License: 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 4
@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 5
Source Project: ZTuoExchange_framework   Source File: AssetController.java    License: 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 6
Source Project: ZTuoExchange_framework   Source File: MemberController.java    License: 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 7
@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 8
@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 9
@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 10
@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 11
Source Project: ZTuoExchange_framework   Source File: BusinessAuthController.java    License: 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 12
@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 13
/**
 * 验证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 14
Source Project: ZTuoExchange_framework   Source File: FavorController.java    License: 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 15
@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 16
@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 17
Source Project: ZTuoExchange_framework   Source File: RegisterController.java    License: 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 18
Source Project: ZTuoExchange_framework   Source File: AssetController.java    License: 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 19
Source Project: ZTuoExchange_framework   Source File: AssetController.java    License: 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 20
@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
@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 22
@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 23
Source Project: ZTuoExchange_framework   Source File: MemberController.java    License: 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 24
Source Project: ZTuoExchange_framework   Source File: PromotionController.java    License: 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 25
@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 26
Source Project: ZTuoExchange_framework   Source File: BusinessAuthController.java    License: 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 27
@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 28
@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
/**
 * 验证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 30
/**
 * 绑定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("绑定失败");
        }
    }
}