Exemplo n.º 1
0
        public PaidService GetPaidServiceDetail(int serviceId, out PlatformUser serviceOwner)
        {
            // вернуть сервис и прогрессивную шкалу расценок
            var list = GetServicesByUserOrId(serviceId, false, out serviceOwner);

            return(list.Count == 0 ? null : list[0]);
        }
Exemplo n.º 2
0
 public AuthenticationResponse GetUserDetail(string login, string password, out PlatformUser userDecorated)
 {
     userDecorated = null;
     using (var dbContext = DatabaseContext.Instance.Make())
     {
         try
         {
             var user = dbContext.PLATFORM_USER.FirstOrDefault(u => u.Login == login);
             if (user == null)
             {
                 return(AuthenticationResponse.InvalidAccount);
             }
             if (user.Password != password)
             {
                 return(AuthenticationResponse.WrongPassword);
             }
             userDecorated = LinqToEntity.DecoratePlatformUser(user);
             return(AuthenticationResponse.OK);
         }
         catch (Exception ex)
         {
             Logger.ErrorFormat("Ошибка в GetUserDetail({0}) : {1}", login, ex);
             return(AuthenticationResponse.ServerError);
         }
     }
 }
Exemplo n.º 3
0
 public List <Transfer> GetAllUserPayments(ProtectedOperationContext ctx, PlatformUser user, out WalletError error)
 {
     error = WalletError.OK;
     if (Channel == null)
     {
         throw new Exception("WalletManagerProxy: связь не установлена");
     }
     try
     {
         return(Channel.GetAllUserPayments(ctx, user, out error));
     }
     catch
     {
         RenewFactory();
         try
         {
             return(Channel.GetAllUserPayments(ctx, user, out error));
         }
         catch (Exception ex2)
         {
             Logger.Error("GetAllUserPayments() error: ", ex2);
             return(null);
         }
     }
 }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> Post(CreateSuperUserDTO model)
        {
            if (string.IsNullOrEmpty(model.Email))
            {
                return(BadRequest("Email address is required"));
            }

            if (string.IsNullOrEmpty(model.Password))
            {
                return(BadRequest("Password is required"));
            }

            var platformUser = new PlatformUser
            {
                Id        = Guid.NewGuid(),
                UserName  = model.Email,
                Email     = model.Email,
                FirstName = model.FirstName,
                Surname   = model.Surname
            };

            try
            {
                UnitOfWork.UserManager.AddOrUpdateUser(platformUser, model.Password);
                await UnitOfWork.UserManager.AddToRoleAsync(platformUser.Id, Role.PLATFORM_ADMINISTRATOR);

                MemoryCacher.Delete(CACHE_KEY);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemplo n.º 5
0
 public PaidService GetPaidServiceDetail(int serviceId, out PlatformUser serviceOwner)
 {
     serviceOwner = null;
     if (Channel == null)
     {
         throw new Exception("WalletManagerProxy: связь не установлена");
     }
     try
     {
         return(Channel.GetPaidServiceDetail(serviceId, out serviceOwner));
     }
     catch
     {
         RenewFactory();
         try
         {
             return(Channel.GetPaidServiceDetail(serviceId, out serviceOwner));
         }
         catch (Exception ex2)
         {
             Logger.Error("GetPaidServiceDetail() error: ", ex2);
             return(null);
         }
     }
 }
Exemplo n.º 6
0
 public CreateReadonlyUserRequestStatus MakeOrDeleteReadonlyUser(ProtectedOperationContext secCtx,
                                                                 int accountId, bool makeNew, string pwrd,
                                                                 out PlatformUser user)
 {
     user = null;
     return(CreateReadonlyUserRequestStatus.CommonError);
 }
Exemplo n.º 7
0
        public List <Transfer> GetAllUserPayments(ProtectedOperationContext secCtx, PlatformUser user, out WalletError error)
        {
            if (!UserSessionStorage.Instance.PermitUserOperation(secCtx, false, false))
            {
                error = WalletError.InsufficientRights;
                return(null);
            }

            error = WalletError.ServerError;
            var transfers = new List <Transfer>();

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var queryTrans = (from trans in ctx.TRANSFER where trans.User == user.ID select trans).ToList().Select(
                        LinqToEntity.DecorateTransfer).ToList();
                }

                return(transfers);
            }
            catch (Exception ex)
            {
                Logger.Error("GetAllUserPayments() error", ex);
                error = WalletError.ServerError;
                return(null);
            }
        }
Exemplo n.º 8
0
        // todo display errors
        public async Task <IActionResult> OnPost(
            [FromServices] SignInManager <PlatformUser> signInManager,
            [FromServices] UserManager <PlatformUser> userManager)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = new PlatformUser
            {
                UserName = Form.Email,
                Email    = Form.Email,
            };

            var createUserResult = await userManager.CreateAsync(user, Form.Password);

            if (!createUserResult.Succeeded)
            {
                return(Page());
            }

            await signInManager.SignInAsync(user, false);

            if (Form.ReturnUrl is { Length : > 0 })
Exemplo n.º 9
0
        public Account GetAccountDetail(string hash, string userLogin, long localTime,
                                        int accountId, bool calculateEquity,
                                        out decimal brokerLeverage, out decimal exposure)
        {
            brokerLeverage = 0;
            exposure       = 0;

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var user = ctx.PLATFORM_USER.FirstOrDefault(u => u.Login == userLogin);
                    if (user == null)
                    {
                        return(null);
                    }

                    var userHash = CredentialsHash.MakeCredentialsHash(userLogin, user.Password, localTime);
                    if (userHash != hash)
                    {
                        return(null);
                    }

                    // авторизован?
                    if (!PlatformUser.IsManager(user.RoleMask) && !PlatformUser.IsAdmin(user.RoleMask))
                    {
                        if (!ctx.PLATFORM_USER_ACCOUNT.Any(pa => pa.PlatformUser == user.ID && pa.Account == accountId))
                        {
                            return(null);
                        }
                    }

                    var account = LinqToEntity.DecorateAccount(ctx.ACCOUNT.First(a => a.ID == accountId));
                    if (!calculateEquity)
                    {
                        return(account);
                    }

                    // получить открытые ордера по счету
                    var orders = ctx.POSITION.Where(p => p.AccountID == accountId && p.State ==
                                                    (int)PositionState.Opened).ToList().Select(LinqToEntity.DecorateOrder).ToList();

                    // посчитать открытый результат и экспозицию в валюте депо
                    var quotes = QuoteStorage.Instance.ReceiveAllData();
                    var errors = new List <string>();
                    exposure = DalSpot.Instance.CalculateExposure(orders, quotes, account.Currency, errors);
                    var group = ctx.ACCOUNT_GROUP.First(g => g.Code == account.Group);
                    brokerLeverage     = group.BrokerLeverage;
                    account.UsedMargin = exposure / brokerLeverage;
                    return(account);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка в GetAccountDetail()", ex);
                return(null);
            }
        }
    // Use this for initialization
    void Start()
    {
        Debug.Log("In Editor, Logging in as Test User with access token: " + GameAuthentication.GetAppID());
        var socialPlayUserObj = new PlatformUser();

        socialPlayUserObj.appID          = new Guid(GameAuthentication.GetAppID());
        socialPlayUserObj.platformID     = 1;
        socialPlayUserObj.platformUserID = "2";
        socialPlayUserObj.userName       = "******";
        Systems.UserGetter.GetSocialPlayUser(socialPlayUserObj, GameAuthentication.OnUserAuthorized);
    }
Exemplo n.º 11
0
 public User(PlatformUser user)
 {
     ID          = user.ID;
     Title       = user.Title;
     Name        = user.Name;
     Surname     = user.Surname;
     Patronym    = user.Patronym;
     Description = user.Description;
     Login       = user.Login;
     RoleMask    = user.RoleMask;
 }
Exemplo n.º 12
0
    public void GetSocialPlayUser(PlatformUser socialPlayUser, Action <WebserviceCalls.UserInfo> callback)
    {
        WebserviceCalls webserviceCalls = GameObject.FindObjectOfType(typeof(WebserviceCalls)) as WebserviceCalls;

        //todo remove email
        webserviceCalls.GetUserFromWorld(socialPlayUser.appID, socialPlayUser.platformID, socialPlayUser.platformUserID, socialPlayUser.userName, null, (WebserviceCalls.UserInfo x) =>
        {
            WebserviceCalls.UserInfo userGuid = x;
            callback(userGuid);
        });
    }
Exemplo n.º 13
0
        private static void MakeEmail(PlatformUser us)
        {
            var domain = mailDomains.GetRandomValue();

            // имя вида [email protected]
            if (rand.Next(100) < 30)
            {
                if (rand.Next(100) < 60)
                {
                    us.Email = Transliteration.Front(us.Name) + "." + Transliteration.Front(us.Surname) + domain;
                }
                else // либо [email protected]
                {
                    us.Email = Transliteration.Front(us.Surname) + "." + Transliteration.Front(us.Name) + domain;
                }
                return;
            }

            // имя вида [email protected]
            if (rand.Next(100) < 40)
            {
                us.Email = Transliteration.Front(us.Name[0].ToString()) + Transliteration.Front(us.Surname);
                // или [email protected]
                if (rand.Next(100) < 66)
                {
                    us.Email += (1996 - rand.Next(25));
                }
                else
                {
                    us.Email += (1996 - rand.Next(25)).ToString().Substring(2, 2);
                }
                us.Email += domain;
                return;
            }

            // имя из логина [email protected]
            if (rand.Next(100) < 65)
            {
                us.Email = us.Login + domain;
                return;
            }

            // [email protected] или [email protected]
            us.Email = us.Login;
            if (rand.Next(100) < 66)
            {
                us.Email += (1996 - rand.Next(25));
            }
            else
            {
                us.Email += (1996 - rand.Next(25)).ToString().Substring(2, 2);
            }
            us.Email += domain;
        }
        public async Task SaveAsync(PlatformUser user, Connection connection)
        {
            using (IAsyncDocumentSession session = _documentStore.OpenAsyncSession())
            {
                await session.StoreAsync(user);

                var upd = DateTime.UtcNow; // Do we need to adjust for time passed during the update request?
                connection.LastUpdatedUtc = IsoDateTimeUtc.FromDateTime(new DateTime(upd.Year, upd.Month, upd.Day, upd.Hour, upd.Minute, 0));
                await session.StoreAsync(connection);

                await session.SaveChangesAsync();
            }
        }
Exemplo n.º 15
0
 public RequestStatus QueryReadonlyUserForAccount(ProtectedOperationContext secCtx, int accountId,
                                                  out PlatformUser user)
 {
     try
     {
         return(Proxy.QueryReadonlyUserForAccount(secCtx, accountId, out user));
     }
     catch (Exception)
     {
         RenewChannel();
         return(Proxy.QueryReadonlyUserForAccount(secCtx, accountId, out user));
     }
 }
Exemplo n.º 16
0
        private static string GetPerformedBy(PlatformUser user)
        {
            if (!string.IsNullOrEmpty(user.NationalIdentityNumber))
            {
                return(user.NationalIdentityNumber);
            }
            else if (!string.IsNullOrEmpty(user.OrgId))
            {
                return(user.OrgId);
            }

            return(string.Empty);
        }
Exemplo n.º 17
0
    public void LoginWithPlatformUser(Guid AppID, int platformID, string platformUserID, string userName)
    {
        PlatformUser platformUser = new PlatformUser();

        platformUser.appID          = AppID;
        platformUser.platformID     = platformID;
        platformUser.platformUserID = platformUserID;
        platformUser.userName       = userName;

        SocialPlayUserWebServiceGetter userGetter = new SocialPlayUserWebServiceGetter();

        userGetter.GetSocialPlayUser(platformUser, OnReceivedUserInfo);
    }
Exemplo n.º 18
0
 public CreateReadonlyUserRequestStatus MakeOrDeleteReadonlyUser(ProtectedOperationContext secCtx,
                                                                 int accountId, bool makeNew, string pwrd,
                                                                 out PlatformUser user)
 {
     try
     {
         return(Proxy.MakeOrDeleteReadonlyUser(secCtx, accountId, makeNew, pwrd, out user));
     }
     catch (Exception)
     {
         RenewChannel();
         return(Proxy.MakeOrDeleteReadonlyUser(secCtx, accountId, makeNew, pwrd, out user));
     }
 }
Exemplo n.º 19
0
        private List <PaidService> GetServicesByUserOrId(int id, bool byUser, out PlatformUser serviceOwner)
        {
            serviceOwner = null;
            var srvList = new List <PaidService>();

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var query = byUser
                                    ? ctx.SERVICE.Where(s => s.User == id)
                                    : ctx.SERVICE.Where(s => s.ID == id);
                    foreach (var srv in query)
                    {
                        var paidServ = LinqToEntity.DecoratePaidService(srv);
                        var srvId    = srv.ID;
                        // добавить рейты
                        foreach (var rate in ctx.SERVICE_RATE.Where(r => r.Service == srvId))
                        {
                            paidServ.serviceRates.Add(new PaidServiceRate
                            {
                                Amount      = rate.Amount,
                                RateType    = (PaidServiceRate.ServiceRateType)rate.RateType,
                                UserBalance = rate.UserBalance
                            });
                        }
                        srvList.Add(paidServ);
                    }

                    if (byUser)
                    {
                        serviceOwner = LinqToEntity.DecoratePlatformUser(ctx.PLATFORM_USER.First(u => u.ID == id));
                    }
                    else
                    {
                        var srv = srvList.FirstOrDefault();
                        if (srv != null)
                        {
                            serviceOwner = LinqToEntity.DecoratePlatformUser(ctx.PLATFORM_USER.First(u => u.ID == srv.User));
                        }
                    }
                }
                return(srvList);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("GetServicesByUserOrId({0}, {1}) error: {2}", id, byUser, ex);
                return(srvList);
            }
        }
Exemplo n.º 20
0
        public static async Task <IdentityResult> CreateUser(PlatformUser user, string password)
        {
            var userManager = new UserManager <PlatformUser>(
                new UserStore <PlatformUser>(new PlatformUserIdentityDbContext()));

            //Allows for use of email address as username:
            userManager.UserValidator = new UserValidator <PlatformUser>(userManager)
            {
                AllowOnlyAlphanumericUserNames = false
            };


            var idResult = await userManager.CreateAsync(user, password);

            return(idResult);
        }
Exemplo n.º 21
0
        private static bool SendEmailOnNewAccount(PlatformUser user, bool isDemo)
        {
            var sb = new StringBuilder();

            sb.AppendLine(string.Format("Уважаемый {0},", user.MakeFullName()));
            sb.AppendLine();
            sb.AppendLine(string.Format("в платформе {0} открыт {1} для пользователя {2}.",
                                        PlatformConstants.PlatformLongName, isDemo ? "демо-счет" : "счет", user.Login));
            sb.AppendLine(string.Format("Пароль для доступа к счету: {0}.", user.Password));
            sb.AppendLine();
            sb.AppendLine("Спасибо, что выбрали нас!");

            return(HttpMailServerProxy.SendEmails(new[] { user.Email },
                                                  "Регистрация счета в " + PlatformConstants.PlatformShortName,
                                                  sb.ToString(), new string[0]));
        }
Exemplo n.º 22
0
        public AccountRegistrationResponse RegisterAccount(
            string login,
            string password,
            string email,
            string firstName,
            string lastName,
            string patronym,
            string phone,
            string currency, int startBalance)
        {
            var usr = new PlatformUser
            {
                Login            = login,
                Password         = password,
                Email            = email,
                Name             = firstName,
                Surname          = lastName,
                Patronym         = patronym,
                Phone1           = phone,
                RegistrationDate = DateTime.Now
            };

            var resp = new AccountRegistrationResponse();

            if (currency != "USD")
            {
                resp.errors.Add("Поддерживаемые валюты: " + "USD");
            }
            //if (!PlatformUser.CheckLoginSpelling(usr.Login))
            //    resp.errors.Add("Логин задан некорректно");
            if (resp.errors.Count > 0)
            {
                return(resp);
            }

            var status = ManagerAccount.Instance.RegisterAccount(usr,
                                                                 currency, startBalance < 1000 ? 1000 : startBalance, 0, usr.Password, false);

            resp.status     = status;
            resp.statusName = EnumFriendlyName <AccountRegistrationStatus> .GetString(status);

            return(resp);
        }
Exemplo n.º 23
0
    void UserNameCallBack(FBResult response)
    {
        Dictionary <string, object> FBInfo = Facebook.MiniJSON.Json.Deserialize(response.Text) as Dictionary <string, object>;

        if (string.IsNullOrEmpty(response.Error))
        {
            var socialPlayUserObj = new PlatformUser();
            socialPlayUserObj.appID          = new Guid(GameAuthentication.GetAppID());
            socialPlayUserObj.platformID     = 1;
            socialPlayUserObj.platformUserID = FB.UserId;
            socialPlayUserObj.userName       = FBInfo["first_name"].ToString();
            Systems.UserGetter.GetSocialPlayUser(socialPlayUserObj, GameAuthentication.OnUserAuthorized);

            if (OnRecivedUserInfo != null)
            {
                OnRecivedUserInfo();
            }
        }
    }
Exemplo n.º 24
0
 public AuthenticationResponse GetUserDetail(string login, string password, out PlatformUser user)
 {
     user = null;
     try
     {
         return(Proxy.GetUserDetail(login, password, out user));
     }
     catch (Exception)
     {
         RenewChannel();
         try //no try-catch in original
         {
             return(Proxy.GetUserDetail(login, password, out user));
         }
         catch (Exception)
         {
             return(AuthenticationResponse.ServerError);
         }
     }
 }
Exemplo n.º 25
0
        private List <PlatformUser> MakeUsersWithNames()
        {
            var users = new List <PlatformUser>();
            var pwrd  = tbPassword.Text;

            foreach (var line in tbUserNames.Lines)
            {
                if (string.IsNullOrEmpty(line) || line.Length < 10)
                {
                    continue;
                }
                var parts = line.Split(
                    new[] { ' ', (char)Keys.Tab, ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 3)
                {
                    continue;
                }

                var login = parts.FirstOrDefault(p => (p[0] >= 'a' && p[0] <= 'z') || (p[0] >= 'A' && p[0] <= 'Z'));
                if (string.IsNullOrEmpty(login))
                {
                    continue;
                }

                parts = parts.Except(new[] { login }).ToArray();
                var user = new PlatformUser
                {
                    Login            = login,
                    Name             = parts[0],
                    Surname          = parts[1],
                    Password         = pwrd,
                    Title            = "Trader",
                    RightsMask       = UserAccountRights.Trade,
                    RegistrationDate = DateTime.Now
                };
                MakeEmail(user);
                users.Add(user);
            }

            return(users);
        }
Exemplo n.º 26
0
        public static PLATFORM_USER UndecoratePlatformUser(PlatformUser user)
        {
            var us = new PLATFORM_USER
            {
                ID               = user.ID,
                Title            = user.Title,
                Login            = user.Login,
                Name             = user.Name,
                Password         = user.Password,
                Patronym         = user.Patronym,
                Phone1           = user.Phone1,
                Phone2           = user.Phone2,
                RoleMask         = (int)user.RoleMask,
                Surname          = user.Surname,
                Description      = user.Description,
                Email            = user.Email,
                RegistrationDate = user.RegistrationDate
            };

            return(us);
        }
Exemplo n.º 27
0
    public void LinkCallback(string platformUserInfo)
    {
        var jobject = JObject.Parse(platformUserInfo);

        var isGuest = (bool)jobject["isGuest"];

        if (isGuest)
        {
            if (OnGuestModeActivated != null)
            {
                OnGuestModeActivated();
            }

            return;
        }

        var userinfo = new PlatformUser();

        try
        {
            userinfo.platformUserID = jobject["userID"].ToString();
            userinfo.userName       = jobject["userName"].ToString();
            userinfo.platformID     = int.Parse(jobject["platformID"].ToString());
            userinfo.appID          = Systems.AppId;
        }
        catch (Exception)
        {
            throw new Exception("Platform web script has passed in incorrect data");
        }

        Systems.UserGetter.GetSocialPlayUser(userinfo, (user) =>
        {
            if (OnRecievedUser != null)
            {
                OnRecievedUser(user);
            }
        });
    }
Exemplo n.º 28
0
        public RequestStatus QueryReadonlyUserForAccount(ProtectedOperationContext secCtx, int accountId,
                                                         out PlatformUser user)
        {
            user = null;

            if (UserOperationRightsStorage.IsProtectedOperation(UserOperation.GetAccountDetail))
            {
                if (
                    !UserSessionStorage.Instance.PermitUserOperation(secCtx,
                                                                     UserOperationRightsStorage.IsTradeOperation(
                                                                         UserOperation.GetAccountDetail), false))
                {
                    return(RequestStatus.Unauthorized);
                }
            }

            try
            {
                using (var ctx = DatabaseContext.Instance.Make())
                {
                    var existingUserRecord = ctx.PLATFORM_USER_ACCOUNT.FirstOrDefault(ua => ua.Account == accountId &&
                                                                                      ua.RightsMask ==
                                                                                      (int)AccountRights.Просмотр);
                    if (existingUserRecord != null)
                    {
                        user = LinqToEntity.DecoratePlatformUser(ctx.PLATFORM_USER.First(u => u.ID == existingUserRecord.PlatformUser));
                    }
                    return(RequestStatus.OK);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Ошибка в QueryReadonlyUserForAccount()", ex);
                return(RequestStatus.CommonError);
            }
        }
Exemplo n.º 29
0
 public RequestStatus QueryReadonlyUserForAccount(ProtectedOperationContext secCtx, int accountId, out PlatformUser user)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 30
0
 public CreateReadonlyUserRequestStatus MakeOrDeleteReadonlyUser(ProtectedOperationContext secCtx, int accountId, bool makeNew,
                                                                 string pwrd, out PlatformUser user)
 {
     throw new NotImplementedException();
 }