示例#1
0
        public string SendCode([FromBody] JObject value)
        {
            try
            {
                if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_SEND_CODE_ACTION))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];


                var code = "";
                if (value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE))
                {
                    code = value[ParseDataKeyApi.KEY_PASS_DATA_GET_CODE].ToString();
                }

                if (userModel.IsTwoFactor == 1)
                {
                    if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                    }

                    if (!HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                    }
                }


                var    action = value[ParseDataKeyApi.KEY_TWO_FA_SEND_CODE_ACTION].ToString();
                string secret;
                var    time = 30;

                switch (action)
                {
                case ActionLog.TWOFA_ENABLE:
                    secret = ActionLog.TWOFA_ENABLE;
                    break;

                case ActionLog.CUSTOM_TWOFA:
                    secret = ActionLog.CUSTOM_TWOFA;
                    break;

                case ActionLog.AVATAR:
                    secret = ActionLog.AVATAR;
                    break;

                case ActionLog.UPDATE_PREFERENCES:
                    secret = ActionLog.UPDATE_PREFERENCES;
                    break;

                case ActionLog.UPDATE_OPTION_VETIFY:
                    secret = ActionLog.UPDATE_OPTION_VETIFY;
                    break;

                case ActionLog.UPDATE_PROFILE:
                    secret = ActionLog.UPDATE_PROFILE;
                    break;

                case ActionLog.TWOFA_DISABLE:
                    secret = ActionLog.TWOFA_DISABLE;
                    break;

                case ActionLog.LOCK_SCREEN:
                    secret = ActionLog.LOCK_SCREEN;
                    break;

                case ActionLog.SEND_TRANSACTION:
                    secret = ActionLog.SEND_TRANSACTION;
                    break;

                case ActionLog.API_ACCESS_ADD:
                    secret = ActionLog.API_ACCESS_ADD;
                    time   = 120;
                    break;

                case ActionLog.API_ACCESS_EDIT:
                    secret = ActionLog.API_ACCESS_EDIT;
                    time   = 120;
                    break;

                case ActionLog.API_ACCESS_STATUS:
                    secret = ActionLog.API_ACCESS_STATUS;
                    break;

                case ActionLog.API_ACCESS_DELETE:
                    secret = ActionLog.API_ACCESS_DELETE;
                    break;

                default:

                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }


                var checkSecret = HelpersApi.CheckToken(userModel, secret);

                if (checkSecret == null)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.SMS_ERROR));
                }

                if (checkSecret.NewSecret == null)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.SMS_ERROR));
                }

                if (checkSecret.Secret == null)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.SMS_ERROR));
                }

                userModel.SecretAuthToken = checkSecret.NewSecret;
                var resultUpdate = _userBusiness.UpdateProfile(userModel);

                return(resultUpdate.Status == Status.STATUS_ERROR
                    ? resultUpdate.ToJson()
                    : _userBusiness.SendSms(userModel, HelpersApi.SendCodeSms(checkSecret.Secret, time)).ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.TWOFA_REQUIRED_SEND_CODE + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }