Ejemplo n.º 1
0
 public static int tokenToUserId(string token)
 {
     if (token != null)
     {
         return(DB_Tools.nameToUserid(token.Substring(6, token.Length - 15)));
     }
     return(-1);
 }
Ejemplo n.º 2
0
        public static Response editUserData(Request req)
        {
            int userid = tokenToUserId(req.token);

            if (userid != -1)
            {
                if (DB_Tools.nameToUserid(req.loc.Substring(7).Trim()) == userid)
                {
                    if (req.ctype == "json")
                    {
                        JObject jObject = JObject.Parse(req.payload);
                        string  nickname = null, bio = null, email = null, image = null;
                        if (jObject.GetValue("Nickname") != null)
                        {
                            nickname = jObject.GetValue("Nickname").ToString();
                        }
                        if (jObject.GetValue("Bio") != null)
                        {
                            bio = jObject.GetValue("Bio").ToString();
                        }
                        if (jObject.GetValue("Email") != null)
                        {
                            email = jObject.GetValue("Email").ToString();
                        }
                        if (jObject.GetValue("Image") != null)
                        {
                            image = jObject.GetValue("Image").ToString();
                        }
                        DB_Tools.editUserData(userid, nickname, bio, email, image);
                        return(new Response(req, Status_Code.OK, AdditionalPayload: "Edited. "));
                    }
                    return(new Response(req, Status_Code.NOK, AdditionalPayload: "Invalid type. "));
                }
                return(new Response(req, Status_Code.NOK, AdditionalPayload: "Unauthorised request. "));
            }
            return(new Response(req, Status_Code.NOK, AdditionalPayload: "Couldn't verify Connection. "));
        }
Ejemplo n.º 3
0
        public static Response getUserData(Request req)
        {
            int userid = tokenToUserId(req.token);

            if (userid != -1)
            {
                if (DB_Tools.nameToUserid(req.loc.Substring(7).Trim()) == userid)
                {
                    JObject       payload  = new JObject();
                    List <string> userData = DB_Tools.userData(DB_Tools.nameToUserid(req.loc.Substring(7).Trim()));
                    foreach (string data in userData)
                    {
                        string[] lines = data.Split("\r\n");
                        if (lines.Length == 2)
                        {
                            payload.Add(lines[0], lines[1]);
                        }
                    }
                    return(new Response(req, Status_Code.OK, AdditionalPayload: payload.ToString()));
                }
                return(new Response(req, Status_Code.NOK, AdditionalPayload: "Unauthorised request. "));
            }
            return(new Response(req, Status_Code.NOK, AdditionalPayload: "Couldn't verify Connection. "));
        }
Ejemplo n.º 4
0
 public virtual int finishResult(List <user_battle_info> active_users)
 {
     DB_Tools.incrementUserWin(DB_Tools.nameToUserid(active_users[0].username));
     return(DB_Tools.nameToUserid(active_users[0].username));;
 }