public string GetActivity()
        {
            try
            {
                var queryStringValue = Request.Query;
                var userModel        = (User)RouteData.Values["UserModel"];

                if (!queryStringValue.ContainsKey("offset") || !queryStringValue.ContainsKey("limit"))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                StringValues sort;
                StringValues filter;
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_OFFSET, out var offset);
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_LIMIT, out var limit);
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER, out filter);
                }
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT, out sort);
                }
                sort = ConvertSortLog(sort);

                if (userModel != null)
                {
                    int numberData;
                    var resultLogs = _userBusiness.GetActionLog(out numberData, userModel.Id, Convert.ToInt32(offset),
                                                                Convert.ToInt32(limit), filter.ToString(), sort);
                    if (resultLogs.Status != Status.STATUS_SUCCESS)
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.DATA_NOT_FOUND));
                    }

                    var listLogs = JsonHelper.DeserializeObject <List <UserActionLog> >(resultLogs.Data);
                    return(new ReturnObject
                    {
                        Status = Status.STATUS_SUCCESS,
                        Data = new ResultList <UserActionLog>
                        {
                            List = listLogs,
                            Total = numberData
                        }.ToJson()
                    }.ToJson());
                }

                return(HelpersApi.CreateDataError(MessageApiError.DATA_NOT_FOUND));
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.LOG_LIST + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }
 public string DeleteUserActivityById([FromBody] JObject value)
 {
     try
     {
         return(value.ContainsKey("Id")
             ? _userBusiness.DeleteActivityById(value["Id"].ToString()).ToJson()
             : HelpersApi.CreateDataError("ID Not exist."));
     }
     catch (Exception e)
     {
         _logger.Error(KeyLogger.LOG_DELETE + e);
         return(HelpersApi.CreateDataError(e.Message));
     }
 }
Esempio n. 3
0
        public string UpdatePreferences([FromBody] JObject value)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

                if (value.ContainsKey(ParseDataKeyApi.KEY_USER_UPDATE_PREFERENCES_CURRENCY))
                {
                    var currencyKey = value[ParseDataKeyApi.KEY_USER_UPDATE_PREFERENCES_CURRENCY].ToString();
                    if (!string.IsNullOrEmpty(currencyKey) &&
                        PaymentCurrency.LIST_CURRENCY.ContainsKey(currencyKey))
                    {
                        userModel.CurrencyKey = currencyKey;
                    }
                    else
                    {
                        return(CreateDataError("Currency Key is not exist"));
                    }
                }

                if (value.ContainsKey(ParseDataKeyApi.KEY_USER_UPDATE_PREFERENCES_TIMEZONE))
                {
                    var timezoneKey = value[ParseDataKeyApi.KEY_USER_UPDATE_PREFERENCES_TIMEZONE].ToString();
                    if (!string.IsNullOrEmpty(timezoneKey) && Timezone.LIST_TIME_ZONE.ContainsKey(timezoneKey))
                    {
                        userModel.TimezoneKey = timezoneKey;
                    }
                    else
                    {
                        return(CreateDataError("Timezone Key is not exist"));
                    }
                }

                _userBusiness.UpdateProfile(userModel);

                //save action log
                return(_userBusiness.AddActionLog(userModel.Email, userModel.Id,
                                                  ActionLog.UPDATE_PREFERENCES,
                                                  HelpersApi.GetIp(Request)).ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.USER_UPDATE_PREFERENCES + e);
                return(CreateDataError(e.Message));
            }
        }
Esempio n. 4
0
        public string UpdateCloseAccount([FromBody] JObject value)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

                if (
                    !value.ContainsKey(ParseDataKeyApi.KEY_SECURITY_UPDATE_CLOSE_ACCOUNT_STATUS) ||
                    !value.ContainsKey(ParseDataKeyApi.KEY_SECURITY_UPDATE_CLOSE_ACCOUNT_PASSWORD))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID + 1));
                }

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

                var status = value[ParseDataKeyApi.KEY_SECURITY_UPDATE_CLOSE_ACCOUNT_STATUS];

                if (!int.TryParse((string)status, out var outStatus))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID + 2));
                }

                var password = value[ParseDataKeyApi.KEY_SECURITY_UPDATE_CLOSE_ACCOUNT_PASSWORD].ToString();

                if (!HelpersApi.ValidateSecondPass(password))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID + 3));
                }

                if (userModel.IsLockScreen != 0)
                {
                    if (!CommonHelper.Md5(password).Equals(userModel.SecondPassword))
                    {
                        return new ReturnObject
                               {
                                   Status  = Status.STATUS_ERROR,
                                   Message = "Pass is invalid"
                               }
                    }
                    .ToJson();
                }
Esempio n. 5
0
        public string UpdateUserProfile([FromBody] JObject value)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

                if (value.ContainsKey(ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_ADDRESS_1))
                {
                    userModel.StreetAddress1 = value[ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_ADDRESS_1].ToString();
                }

                if (value.ContainsKey(ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_ADDRESS_2))
                {
                    userModel.StreetAddress2 = value[ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_ADDRESS_2].ToString();
                }

                if (value.ContainsKey(ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_CITY))
                {
                    userModel.City = value[ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_CITY].ToString();
                }

                if (value.ContainsKey(ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_POSTAL_CODE))
                {
                    userModel.PostalCode = value[ParseDataKeyApi.KEY_USER_UPDATE_PROFILE_POSTAL_CODE].ToString();
                }

                _userBusiness.UpdateProfile(userModel);

                //save action log
                return(_userBusiness.AddActionLog(userModel.Email, userModel.Id,
                                                  ActionLog.UPDATE_PROFILE,
                                                  HelpersApi.GetIp(Request)).ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.USER_UPDATE + e);
                return(CreateDataError(e.Message));
            }
        }
Esempio n. 6
0
        public string GetInfo()
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = JsonHelper.SerializeObject(new SecurityModel
                    {
                        TwofaOption = userModel.Verification,
                        IsEnableTwofa = userModel.IsTwoFactor
                    })
                }.ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.SECURITY_GET_INFO + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }
Esempio n. 7
0
        public string GetInfo()
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

                if (userModel != null)
                {
                    return(new ReturnObject
                    {
                        Status = Status.STATUS_SUCCESS,
                        Data = JsonConvert.SerializeObject(new InfoApi())
                    }.ToJson());
                }

                return(HelpersApi.CreateDataError(MessageApiError.DATA_NOT_FOUND));
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.API_ACCESS_GET_INFO + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }
Esempio n. 8
0
        public string UpdateNotifications([FromBody] JObject value)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

                if (value.ContainsKey(ParseDataKeyApi.KEY_USER_UPDATE_NOTIFICATION))
                {
                    userModel.Notifications = value[ParseDataKeyApi.KEY_USER_UPDATE_NOTIFICATION].ToString();
                }

                _userBusiness.UpdateProfile(userModel);

                return(_userBusiness.AddActionLog(userModel.Email, userModel.Id,
                                                  ActionLog.UPDATE_NOTIFICATION,
                                                  HelpersApi.GetIp(Request)).ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.USER_UPDATE_NOTIFICATION + e);
                return(CreateDataError(e.Message));
            }
        }
Esempio n. 9
0
        public string UpdateLabel([FromBody] JObject value)
        {
            try
            {
                if (!value.ContainsKey("id") || !value.ContainsKey("networkName"))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                var id          = value["id"].ToString();
                var networkName = value["networkName"].ToString();

                if (!HelpersApi.ValidateCurrency(networkName))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                if (!CommonHelper.ValidateId(id))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                if (value.ContainsKey("label"))
                {
                    var label  = value["label"].ToString();
                    var result = _walletBusiness.UpdateAddress(id, networkName, label);

                    if (result.Status == Status.STATUS_SUCCESS)
                    {
                        return new ReturnObject
                               {
                                   Status = Status.STATUS_SUCCESS
                               }
                    }
                    .ToJson();
                }
Esempio n. 10
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));
            }
        }
Esempio n. 11
0
        public string GetListApiAccess()
        {
            try
            {
                var queryStringValue = Request.Query;


                if (!queryStringValue.ContainsKey("offset") || !queryStringValue.ContainsKey("limit"))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                StringValues sort = "-updatedat";
                StringValues filter;
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_OFFSET, out var offset);
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_LIMIT, out var limit);
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER, out filter);
                }
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT, out sort);
                }

                sort = ConvertSort(sort);


                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];
                int numberData;
                var dataApiKeys =
                    _userBusiness.GetApiKeys(out numberData, userModel.Id, Convert.ToInt32(offset),
                                             Convert.ToInt32(limit), filter.ToString(), sort);

                if (dataApiKeys.Status != Status.STATUS_SUCCESS)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.DATA_NOT_FOUND));
                }
                var listApiKeys = JsonHelper.DeserializeObject <List <ResultApiAccess> >(dataApiKeys.Data);
                if (listApiKeys.Count <= 0)
                {
                    return new ReturnObject
                           {
                               Status = Status.STATUS_SUCCESS,
                               Data   = JsonHelper.SerializeObject(listApiKeys)
                           }
                }
                .ToJson();
                foreach (var listApiKey in listApiKeys)
                {
                    listApiKey.KeyApi = listApiKey.KeyApi.Substring(0, 10) + "...";
                }

                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = new ResultList <ResultApiAccess>
                    {
                        List = listApiKeys,
                        Total = numberData
                    }.ToJson()
                }.ToJson());
            }
Esempio n. 12
0
        public async Task <string> UploadFile()
        {
            try
            {
                var file = Request.Form.Files[0];


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

                if (file.Length > 2097152)
                {
                    return(CreateDataError("File max size 2Mb"));
                }

                if (file.Length <= 0)
                {
                    return(CreateDataError("Can't update image"));
                }


                using (var w = new WebClient())
                {
                    w.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                    try
                    {
                        using (var m = new MemoryStream())
                        {
                            file.CopyTo(m);
                            m.Close();
                            // Convert byte[] to Base64 String
                            var base64String = Convert.ToBase64String(m.GetBuffer());

                            var values = new NameValueCollection
                            {
                                { ParseDataKeyApi.KEY_USER_UPDATE_AVATAR, base64String }
                            };

                            w.Headers.Add("Authorization", "Client-ID " + AppSettingHelper.GetImgurApiKey());

                            byte[] response = await w.UploadValuesTaskAsync(AppSettingHelper.GetImgurUrl(), values);

                            var result = JsonHelper.DeserializeObject <JObject>(Encoding.UTF8.GetString(response));

                            if (!(bool)result["success"])
                            {
                                return(CreateDataError("Save image fail"));
                            }
                            userCheck.Avatar = result["data"]["link"].ToString();
                            var updateUser = _userBusiness.UpdateProfile(userCheck);

                            if (updateUser.Status != Status.STATUS_SUCCESS)
                            {
                                return(CreateDataError("Can't update image"));
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        throw;
                    }

                    //save action log
                    _userBusiness.AddActionLog(userCheck.Email, userCheck.Id,
                                               ActionLog.AVATAR,
                                               HelpersApi.GetIp(Request));

                    return(new ReturnObject
                    {
                        Status = Status.STATUS_SUCCESS,
                        Message = "Upload avatar success ",
                        Data = userCheck.Avatar
                    }.ToJson());
                }
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.USER_AVATAR + e);
                return(CreateDataError(e.Message));
            }
        }
Esempio n. 13
0
        public string VerifyCodeEnable([FromBody] JObject value = null)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

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

                    var code          = value[ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_ENABLE_CODE].ToString();
                    var authenticator = new TwoStepsAuthenticator.TimeAuthenticator();

                    var secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken);

                    if (string.IsNullOrEmpty(secretAuthToken.CustomTwofa))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                    }

                    var isOk = authenticator.CheckCode(secretAuthToken.CustomTwofa, code, userModel);

                    if (!isOk)
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                    }
                }
                else if (userModel.IsTwoFactor == 0)
                {
                    if (value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_ENABLE_CODE))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                    }
                }


                var google = new GoogleAuthen.TwoFactorAuthenticator();

                var secretKey = CommonHelper.RandomString(32);

                var startSetup = google.GenerateSetupCode(userModel.Email, secretKey, 300, 300);

                userModel.TwoFactorSecret = secretKey;
                Console.WriteLine(secretKey);
                var resultUpdate = _userBusiness.UpdateProfile(userModel);

                if (resultUpdate.Status == Status.STATUS_ERROR)
                {
                    return(resultUpdate.ToJson());
                }

                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = startSetup.ManualEntryKey
                }.ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.TWOFA_ENABLE_VERIFY + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }
Esempio n. 14
0
        public string GetAddresses()
        {
            try
            {
                var queryStringValue = Request.Query;


                if (!queryStringValue.ContainsKey("offset") || !queryStringValue.ContainsKey("networkName") ||
                    !queryStringValue.ContainsKey("limit"))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                StringValues sort;
                StringValues filter;
                StringValues networkName;
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_OFFSET, out var offset);
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_LIMIT, out var limit);
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER, out filter);
                }
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT, out sort);
                }

                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_NETWORK, out networkName);
                //sort = ConvertSortLog(sort);

                if (!HelpersApi.ValidateCurrency(networkName))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                var userModel = (User)RouteData.Values["UserModel"];

                var wallet = _walletBusiness.FindByUserAndNetwork(userModel.Id, networkName);
                int numberData;
                var listAddresses = _walletBusiness.GetAddressesFull(out numberData, wallet.Id, networkName,
                                                                     Convert.ToInt32(offset),
                                                                     Convert.ToInt32(limit), filter.ToString(), sort);

                return(new ReturnObject()
                {
                    Status = Status.STATUS_COMPLETED,
                    Data = new ResultList <BlockchainAddress>
                    {
                        List = listAddresses,
                        Total = numberData
                    }.ToJson()
                }.ToJson());
            }
            catch (Exception e)
            {
                return(new ReturnObject()
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                }.ToJson());
            }
        }
Esempio n. 15
0
        public async Task <string> GetCurrentUser()
        {
            try
            {
                var email = User.Claims.Where(c => c.Type == ClaimTypes.Email).Select(c => c.Value)
                            .SingleOrDefault();

                if (string.IsNullOrEmpty(email))
                {
                    return(CreateDataError("Can't not email"));
                }

                var query = new Dictionary <string, string> {
                    { "Email", email }
                };


                var userModel = _userBusiness.GetUserInfo(query);

                var ip = HelpersApi.GetIp(Request);
                IpGeographicalLocation location = null;
                if (!string.IsNullOrEmpty(ip))
                {
                    //get location for ip
                    location = await IpGeographicalLocation.QueryGeographicalLocationAsync(ip);
                }

                if (userModel == null)
                {
                    var jsonUser = User.Claims.Where(c => c.Type == "userInfo").Select(c => c.Value)
                                   .SingleOrDefault();

                    var userClaims = Vakapay.Models.Entities.User.FromJson(jsonUser);
                    userClaims.Notifications = "1,2,3";
                    if (location != null)
                    {
                        if (location.Currency?.Code != null)
                        {
                            userClaims.CurrencyKey = location.Currency.Code;
                        }

                        if (location.TimeZone?.Id != null)
                        {
                            userClaims.TimezoneKey = location.TimeZone.Id;
                        }
                    }

                    var resultData = _userBusiness.Login(userClaims);

                    if (resultData.Status == Status.STATUS_ERROR)
                    {
                        return(CreateDataError(resultData.Message));
                    }


                    userModel = Vakapay.Models.Entities.User.FromJson(resultData.Data);


                    return(_walletBusiness.MakeAllWalletForNewUser(userModel).ToJson());
                }

                if (string.IsNullOrEmpty(ip))
                {
                    return new ReturnObject
                           {
                               Status = Status.STATUS_SUCCESS,
                               Data   = Vakapay.Models.Entities.User.ToJson(userModel)
                           }
                }
                .ToJson();

                UpdateCurrencyAndTimeZone(userModel, location);

                var browser = HelpersApi.GetBrowser(Request);

                var confirmedDevices = new ConfirmedDevices
                {
                    Browser  = browser,
                    Ip       = ip,
                    Location = location != null && !string.IsNullOrEmpty(location.CountryName)
                        ? location.City + "," + location.CountryName
                        : "localhost",
                    UserId = userModel.Id
                };

                var search = new Dictionary <string, string> {
                    { "Ip", ip }, { "Browser", browser }
                };


                //save devices
                var checkConfirmedDevices = _userBusiness.GetConfirmedDevices(search);
                if (checkConfirmedDevices == null)
                {
                    _userBusiness.SaveConfirmedDevices(confirmedDevices);
                }


                userModel.SecretAuthToken = null;
                userModel.TwoFactorSecret = null;
                userModel.SecondPassword  = null;
                userModel.Id          = null;
                userModel.PhoneNumber = !string.IsNullOrEmpty(userModel.PhoneNumber)
                    ? "*********" + userModel.PhoneNumber.Remove(0, 9)
                    : null;
                if (userModel.Birthday.Contains("1900-01-01"))
                {
                    userModel.Birthday = null;
                }

                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = userModel.ToJson()
                }.ToJson());
            }
Esempio n. 16
0
        public string VerifyCodeTransaction([FromBody] JObject value)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];


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

                bool isVerify = false;

                switch (userModel.IsTwoFactor)
                {
                case 1:
                    if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_SMS))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                    }

                    isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, codeGG);
                    break;

                case 2:
                    if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_VERIFY_CODE_TRANSACTION_SMS))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                    }

                    var secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken);
                    if (string.IsNullOrEmpty(secretAuthToken.SendTransaction))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                    }

                    isVerify = HelpersApi.CheckCodeSms(secretAuthToken.SendTransaction, code, userModel);
                    break;

                case 0:
                    isVerify = true;
                    break;
                }

                if (!isVerify)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                }

                // userModel.Verification = (int) option;

                // su ly data gui len
                //to do

                var request = value.ToObject <SendTransaction>();

                var userRequest = new UserSendTransaction()
                {
                    UserId = userModel.Id,
                    Type   = "send",
                    To     = request.Detail.SendByAd
                        ? request.Detail.RecipientWalletAddress
                        : request.Detail.RecipientEmailAddress,
                    SendByBlockchainAddress = request.Detail.SendByAd,
                    Amount       = request.Detail.VkcAmount,
                    PricePerCoin = request.Detail.PricePerCoin,
                    Currency     = request.NetworkName,
                    Description  = request.Detail.VkcNote,
                };
                ReturnObject result = null;
                result = AddSendTransaction(userRequest);

                return(JsonHelper.SerializeObject(result));
            }
            catch (Exception e)
            {
                return(HelpersApi.CreateDataError(e.Message));
            }
        }
Esempio n. 17
0
        public string UpdateOption([FromBody] JObject value)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];

                if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_UPDATE_OPTION))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

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


                bool isVerify = false;

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

                    isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code);
                    break;

                case 2:
                    if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                    }

                    var secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken);
                    if (string.IsNullOrEmpty(secretAuthToken.UpdateOptionVerification))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                    }

                    isVerify = HelpersApi.CheckCodeSms(secretAuthToken.UpdateOptionVerification, code, userModel);
                    break;

                case 0:
                    isVerify = true;
                    break;
                }


                if (!isVerify)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                }

                var option = value[ParseDataKeyApi.KEY_TWO_FA_UPDATE_OPTION];

                userModel.Verification = (int)option;

                _userBusiness.AddActionLog(userModel.Email, userModel.Id,
                                           ActionLog.UPDATE_OPTION_VETIFY,
                                           HelpersApi.GetIp(Request));

                return(_userBusiness.UpdateProfile(userModel).ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.TWOFA_OPTION_UPDATE + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }
Esempio n. 18
0
        public string GetConfirmedDevices()
        {
            try
            {
                var queryStringValue = Request.Query;

                if (!queryStringValue.ContainsKey("offset") || !queryStringValue.ContainsKey("limit"))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                StringValues sort;
                StringValues filter;
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_OFFSET, out var offset);
                queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_LIMIT, out var limit);
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_FILTER, out filter);
                }
                if (queryStringValue.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT))
                {
                    queryStringValue.TryGetValue(ParseDataKeyApi.KEY_PASS_DATA_GET_SORT, out sort);
                }

                sort = ConvertSortDevice(sort);

                var ip = HelpersApi.GetIp(Request);

                var checkConfirmedDevices = new ConfirmedDevices();

                if (!string.IsNullOrEmpty(ip))
                {
                    var browser = HelpersApi.GetBrowser(Request);

                    var search = new Dictionary <string, string> {
                        { "Ip", ip }, { "Browser", browser }
                    };

                    //save web session
                    checkConfirmedDevices = _userBusiness.GetConfirmedDevices(search);
                }

                var userModel = (User)RouteData.Values["UserModel"];

                int numberData;
                var resultDevice = _userBusiness.GetListConfirmedDevices(out numberData, userModel.Id,
                                                                         checkConfirmedDevices,
                                                                         Convert.ToInt32(offset),
                                                                         Convert.ToInt32(limit), sort, filter);

                if (resultDevice.Status != Status.STATUS_SUCCESS)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.DATA_NOT_FOUND));
                }

                var listDevice = JsonHelper.DeserializeObject <List <ConfirmedDevices> >(resultDevice.Data);
                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = new ResultList <ConfirmedDevices>
                    {
                        List = listDevice,
                        Total = numberData
                    }.ToJson()
                }.ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.DEVICE_LIST + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }
        static async Task Main(string[] args)
        {
            var consoleRed   = ConsoleColor.Red;
            var consoleGreen = ConsoleColor.Green;

            HelpersApi.WriteLine("Instagram Auto Unfollow!", consoleGreen);
            HelpersApi.WriteLine("Contact me: [email protected]", consoleGreen);
            Console.WriteLine();

            Console.Write("Username: "******"Password: "******"1.) Unfollow All");
            Console.WriteLine("2.) Unfollow Not Following");
            Console.Write("Select Options (1/2) : ");
            string options = Console.ReadLine();

            Console.Write("Delay (in miliseconds): ");
            if (!int.TryParse(Console.ReadLine(), out int delay))
            {
                HelpersApi.WriteLine($"Error, Not valid arguments.", consoleRed);
                return;
            }

            /* Set Instagram Session */
            UserSessionData sessionData = new UserSessionData()
            {
                UserName = username,
                Password = password
            };

            Actions     instaActions = new Actions(sessionData);
            ActionModel login        = await instaActions.DoLogin();

            HelpersApi.WriteLine("Trying to login ...", consoleGreen);

            /* Login */
            HelpersApi.WriteLine(login.Response);

            /* Login Success */
            if (login.Status == 1)
            {
                isLogin = true;
            }

            /* Login Challange */
            if (login.Status == 2)
            {
                await instaActions.SendCode();

                HelpersApi.WriteLine("Put your code: ");
                string code = Console.ReadLine();

                ActionModel verifyCode = await instaActions.VerifyCode(code);

                HelpersApi.WriteLine(verifyCode.Response);
                if (verifyCode.Status == 1)
                {
                    isLogin = true;
                }
            }

            if (isLogin)
            {
                /* Get Your Instagram Informations */
                IResult <InstaUserInfo> targetInfo = await HelpersApi.InstaApi.UserProcessor
                                                     .GetUserInfoByUsernameAsync(sessionData.UserName);

                string LatestMaxId = "";
                int    i           = 0;

                if (targetInfo.Succeeded)
                {
                    HelpersApi.WriteLine($"[+] Username: {targetInfo.Value.Username} " +
                                         $"| Followers: {targetInfo.Value.FollowerCount} | Followings: {targetInfo.Value.FollowingCount}");
                    Console.WriteLine();

                    while (LatestMaxId != null)
                    {
                        var getFollowings = await HelpersApi.InstaApi.UserProcessor
                                            .GetUserFollowingAsync(sessionData.UserName, PaginationParameters.MaxPagesToLoad(1).StartFromMaxId(LatestMaxId));

                        if (getFollowings.Succeeded)
                        {
                            LatestMaxId = getFollowings.Value.NextMaxId;
                            foreach (InstaUserShort following in getFollowings.Value)
                            {
                                // Unfollow All
                                if (options == "1")
                                {
                                    var unfollow = await instaActions.DoUnfollow(following.Pk);

                                    if (unfollow.Status == 1)
                                    {
                                        HelpersApi.WriteLine($"[{i}] Username: {following.UserName} | Unfollow Success.", consoleGreen);
                                    }
                                    else
                                    {
                                        HelpersApi.WriteLine($"[{i}] Username: {following.UserName} | Unfollow Failed.", consoleRed);
                                    }
                                }
                                else
                                {
                                    /* Get Friendship status */
                                    var getFriendshipStatus = await HelpersApi.InstaApi.UserProcessor.GetFriendshipStatusAsync(following.Pk);

                                    if (getFriendshipStatus.Succeeded)
                                    {
                                        /* if they follow us */
                                        if (getFriendshipStatus.Value.FollowedBy)
                                        {
                                            HelpersApi.WriteLine($"[{i}] Username: {following.UserName} | Skipped.", consoleRed);
                                        }
                                        else
                                        {
                                            var unfollow = await instaActions.DoUnfollow(following.Pk);

                                            if (unfollow.Status == 1)
                                            {
                                                HelpersApi.WriteLine($"[{i}] Username: {following.UserName} | Unfollow Success.", consoleGreen);
                                            }
                                            else
                                            {
                                                HelpersApi.WriteLine($"[{i}] Username: {following.UserName} | Unfollow Failed.", consoleRed);
                                            }
                                        }
                                    }
                                }
                                HelpersApi.WriteLine($"[+] Sleep for {delay} ms");
                                await Task.Delay(delay);

                                i++;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 20
0
        public string CustomTwo([FromBody] JObject value)
        {
            try
            {
                var userModel = (User)RouteData.Values[ParseDataKeyApi.KEY_PASS_DATA_USER_MODEL];
                if (!value.ContainsKey(ParseDataKeyApi.KEY_TWO_FA_UPDATE_STATUS))
                {
                    return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                }

                var status = value[ParseDataKeyApi.KEY_TWO_FA_UPDATE_STATUS];


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


                bool       isVerify = false;
                ActionCode secretAuthToken;

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


                    if ((int)status == 2)
                    {
                        secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken);

                        if (string.IsNullOrEmpty(secretAuthToken.CustomTwofa))
                        {
                            return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                        }


                        isVerify = HelpersApi.CheckCodeSms(secretAuthToken.CustomTwofa, code, userModel);
                    }
                    else if ((int)status == 0)
                    {
                        isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code);
                    }

                    break;

                case 2:
                    if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE))
                    {
                        return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                    }

                    if ((int)status == 0)
                    {
                        secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken);

                        if (string.IsNullOrEmpty(secretAuthToken.CustomTwofa))
                        {
                            return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                        }

                        isVerify = HelpersApi.CheckCodeSms(secretAuthToken.CustomTwofa, code, userModel);
                    }
                    else if ((int)status == 1)
                    {
                        isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code);
                    }

                    break;

                case 0:
                    if ((int)status == 1)
                    {
                        if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE))
                        {
                            return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                        }
                        Console.WriteLine(userModel.TwoFactorSecret);

                        isVerify = HelpersApi.CheckCodeGoogle(userModel.TwoFactorSecret, code);
                    }
                    else if ((int)status == 2)
                    {
                        if (!value.ContainsKey(ParseDataKeyApi.KEY_PASS_DATA_GET_CODE))
                        {
                            return(HelpersApi.CreateDataError(MessageApiError.PARAM_INVALID));
                        }

                        secretAuthToken = ActionCode.FromJson(userModel.SecretAuthToken);
                        if (string.IsNullOrEmpty(secretAuthToken.CustomTwofa))
                        {
                            return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                        }

                        isVerify = HelpersApi.CheckCodeSms(secretAuthToken.CustomTwofa, code, userModel);
                    }

                    break;
                }

                Console.WriteLine(isVerify);

                if (!isVerify)
                {
                    return(HelpersApi.CreateDataError(MessageApiError.SMS_VERIFY_ERROR));
                }

                userModel.IsTwoFactor = (int)status;

                _userBusiness.AddActionLog(userModel.Email, userModel.Id,
                                           ActionLog.TWOFA_ENABLE,
                                           HelpersApi.GetIp(Request));

                return(_userBusiness.UpdateProfile(userModel).ToJson());
            }
            catch (Exception e)
            {
                _logger.Error(KeyLogger.TWOFA_ENABLE_UPDATE + e);
                return(HelpersApi.CreateDataError(e.Message));
            }
        }