Beispiel #1
0
        /// <summary>
        /// Log the user in a group chat
        /// </summary>
        /// <param name="groupName">The name of the group</param>
        /// <returns>IActionResult of the log chat action</returns>
        /// See <see cref="Areas.Alive.Models.ChatLogin"/> to see the response structure
        public IActionResult loginChat([Required] string groupName)
        {
            User user = TokenUserManager.getUserFromToken(HttpContext, _context);

            if (!user.open)
            {
                return(BadRequest(new { error = "YoureBanned" }));
            }
            if (AdminPolicy.isAdmin(user, _context))
            {
                return(BadRequest("notAllowed"));
            }
            Group     group    = new Group();
            UserGroup ugCaller = new UserGroup();

            if (!UserFromGroup.isOnIt(user.id, ref group, groupName, ref ugCaller, _context))
            {
                return(BadRequest());
            }

            try
            {
                _context.Entry(group).Collection("chatMessages").Load();
                ChatLogin retMessages = new ChatLogin();
                retMessages.callerPublicId = user.publicid;
                retMessages.group          = group.name;
                retMessages.userMessages   = filterMessages(group.chatMessages.OrderBy(m => m.time).ToList());

                return(Ok(retMessages));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get a user out of a group
        /// </summary>
        /// <param name="groupName">The name of the group that the user is gonna left</param>
        /// <returns>IActionResult of the leaving group action</returns>
        public async System.Threading.Tasks.Task <IActionResult> leaveGroup(string groupName)
        {
            User user = TokenUserManager.getUserFromToken(HttpContext, _context); //The user who tries to leave the group

            if (!user.open)
            {
                return(BadRequest(new { error = "YoureBanned" }));
            }
            if (AdminPolicy.isAdmin(user, _context))
            {
                return(BadRequest("notAllowed"));
            }
            UserGroup ugCaller = new UserGroup();
            Group     group    = new Group();

            if (!UserFromGroup.isOnIt(user.id, ref group, groupName, ref ugCaller, _context))
            {
                return(BadRequest());
            }
            if (!group.open)
            {
                return(BadRequest(new { error = "GroupBanned" }));
            }
            if (!await QuitUserFromGroup.quitUser(ugCaller, _context, _hub))
            {
                return(StatusCode(500));
            }
            InteractionManager.manageInteraction(user, group, interactionType.LEAVED, _context);

            using (var scope = _scopeFactory.CreateScope())
            {
                var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDBContext>();
                var groupE    = dbContext.Group.Where(g => g.name == groupName);

                if (groupE.Count() == 1)
                {
                    Home.Util.GroupNew.launch(user, group, null, Home.Models.TypeGroupNew.JOIN_LEFT_GROUP, false, _context);
                }
                if (groupE.Count() == 1)
                {
                    Home.Util.GroupNew.launch(user, group, null, Home.Models.TypeGroupNew.JOIN_LEFT_USER, false, _context);
                }
            }

            return(Ok(new { success = "SuccesfullGroupLeave" }));
        }
Beispiel #3
0
        //
        // ──────────────────────────────────────────────────────────────────────────────────
        //   :::::: P U B L I C   F U N C T I O N S : :  :   :    :     :        :          :
        // ──────────────────────────────────────────────────────────────────────────────────
        //

        /// <summary>
        /// Check if a user has bet in a fb
        /// </summary>
        /// <param name="caller">The user who wants do/cancel a user fb</param>
        /// <param name="group">A new group object, to save on it</param>
        /// <param name="groupName">The name of the group</param>
        /// <param name="ugCaller">A new UserGroup object, to save on it</param>
        /// <param name="footballBet">A new FootballBet object, to save on it</param>
        /// <param name="footballBetId">The id of the football bet</param>
        /// <param name="_context">The datbase context</param>
        /// <param name="checkOnlyBet">True to check if the user has bet on the fb, false otherwise</param>
        /// <returns></returns>
        public static bool check(User caller, ref Group group, string groupName, ref UserGroup ugCaller, ref FootballBet footballBet, string footballBetId, ApplicationDBContext _context, bool checkOnlyBet = true)
        {
            if (!UserFromGroup.isOnIt(caller.id, ref group, groupName, ref ugCaller, _context))
            {
                return(false);
            }
            if (!getBet(ref footballBet, footballBetId, group, _context))
            {
                return(false);
            }
            if (checkOnlyBet && !checkUserInBet(footballBet, caller, _context))
            {
                return(false);
            }

            return(true);
        }