Example #1
0
        // __ Impl ____________________________________________________________


        private PlayerNotificationData GetPasswordResetNotifData(IDbConnection c, string email)
        {
            var user = GetUserForEmail(c, email);

            /*var mr = c.QueryMultiple(@"
             *      SELECT u.id, u.name, u.email, u.mobile, u.emailConfirmed FROM users u WHERE email ilike @email;
             *      SELECT id, name, logoImgUrl FROM organizations LIMIT 1;
             *  ", new { email = email });*/
            var mr = c.QueryFirst <PublicOrganization>(@"SELECT id, name, logoImgUrl FROM organizations LIMIT 1;");

            var toUser = user;
            //var toUser = mr.ReadFirst<User>();
            var fromUser = toUser;
            //var org = mr.ReadFirst<PublicOrganization>();
            var org = mr;

            var activationLink = PlayersController.GetActivationLink(Request, mTokenManager, toUser);

            var result = new PlayerNotificationData
            {
                From           = fromUser,
                To             = toUser,
                Org            = org,
                ActivationLink = activationLink,
                Images         = new PlayerInviteImages
                {
                    OrgLogo = Utils.GetUploadUrl(Request, org.LogoImgUrl, org.Id, "org"),
                }
            };

            return(result);
        }
        private PlayerNotificationData GetRefereeNotification(IDbConnection c, IDbTransaction t, long idUser, bool wantsPin)
        {
            var fromId = GetUserId();

            var mr = c.QueryMultiple(@"
                    SELECT u.id, u.name, u.email, u.mobile, u.emailConfirmed FROM users u WHERE id = @idUser;
                    SELECT id, name, logoImgUrl FROM organizations LIMIT 1;
                    SELECT u.id, u.name, u.email, u.mobile FROM users u WHERE id = @idFrom;
                ", new { idUser, idFrom = fromId });

            var toUser   = mr.ReadFirst <User>();
            var org      = mr.ReadFirst <PublicOrganization>();
            var fromUser = mr.ReadFirstOrDefault <User>();

            if (fromUser == null && fromId >= 10000000)
            {
                fromUser = UsersController.GetGlobalAdminForId(fromId);
            }

            if (toUser == null)
            {
                throw new Exception("Error.NotFound.ToUser");
            }
            if (fromUser == null)
            {
                throw new Exception("Error.NotFound.FromUser");
            }
            //if (fromUser == null) fromUser = new User { Id=1, Name=org.Name, Email="*****@*****.**" };

            var activationLink = toUser.EmailConfirmed && !wantsPin ? "" : PlayersController.GetActivationLink(Request, mAuthTokenManager, toUser);
            var activationPin  = toUser.EmailConfirmed && !wantsPin ? "" : UsersController.GetActivationPin(mAuthTokenManager, toUser);

            return(new PlayerNotificationData
            {
                From = fromUser,
                To = toUser,
                Org = org,
                ActivationLink = activationLink,
                ActivationPin = activationPin,
                Images = new PlayerInviteImages
                {
                    OrgLogo = Utils.GetUploadUrl(Request, org.LogoImgUrl, org.Id, "org"),
                }
            });
        }
Example #3
0
        private PlayerNotificationData GetPlayerNotification(IDbConnection c, long idCreator, long idPlayer, long idTeam, bool wantsPin = false, long userId = -1)
        {
            var fromUser = UsersController.GetUserForId(c, idCreator);
            var toUser   = new User {
            };

            if (userId == -1) // User should exitst in current org
            {
                toUser = c.QueryFirst <User>($"SELECT u.id, u.name, u.mobile FROM users u JOIN players p ON p.idUser = u.id AND p.id = {idPlayer};");
                var userToGlobal = UsersController.GetUserForId(c, toUser.Id);
                toUser.Email          = userToGlobal.Email;
                toUser.EmailConfirmed = userToGlobal.EmailConfirmed;
            }
            else // Global User info
            {
                toUser = UsersController.GetUserForId(c, userId);
            }

            var mr = c.QueryMultiple(@"
                    SELECT id, name, logoImgUrl FROM organizations LIMIT 1;
                    SELECT id, name, logoImgUrl FROM teams WHERE id = @idTeam;
                ", new { idFrom = idCreator, idPlayer = idPlayer, idTeam = idTeam });

            // var fromUser = mr.ReadFirst<User>();
            // var toUser = mr.ReadFirst<User>();
            var org  = mr.ReadFirst <PublicOrganization>();
            var team = mr.ReadFirst <Team>();

            if (fromUser == null && idCreator >= 10000000)
            {
                fromUser = UsersController.GetGlobalAdminForId(idCreator);
            }

            if (team == null)
            {
                throw new Exception("Error.NotFound.Team");
            }
            if (toUser == null)
            {
                throw new Exception("Error.NotFound.ToUser");
            }
            if (fromUser == null)
            {
                throw new Exception("Error.NotFound.FromUser");
            }

            var activationLink = toUser.EmailConfirmed && !wantsPin ? "" : PlayersController.GetActivationLink(Request, mAuthTokenManager, toUser);
            var activationPin  = toUser.EmailConfirmed && !wantsPin ? "" : UsersController.GetActivationPin(mAuthTokenManager, toUser);

            return(new PlayerNotificationData
            {
                To = toUser,
                From = fromUser,
                Team = team,
                Org = org,
                ActivationLink = activationLink,
                ActivationPin = activationPin,
                Images = new PlayerInviteImages
                {
                    OrgLogo = Utils.GetUploadUrl(Request, org.LogoImgUrl, org.Id, "org"),
                    TeamLogo = Utils.GetUploadUrl(Request, team.LogoImgUrl, team.Id, "team")
                }
            });
        }