Example #1
0
                public static async Task <bool> IsAdmin(Auth.Auth.User user)
                {
                    if (user.unique_id != null && user.username != null)
                    {
                        var admin = await Get.ByGuid(user.unique_id);

                        if (admin.username == user.username && admin.User_Groups.type == Type.Administrator.ToString())
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
Example #2
0
                /// <summary>
                /// Changes user profile picture when user prompts to change it
                /// </summary>
                /// <param name="user"></param>
                /// <returns></returns>
                public static async Task <string> UserPicture(Auth.Auth.User user)
                {
                    var uData = await db.User_Info.Where(x => x.unique_id == user.unique_id).FirstOrDefaultAsync();

                    if (uData != null)
                    {
                        try
                        {
                            HttpClient client = new HttpClient();
                            var        img    = Image.FromStream(await client.GetStreamAsync(user.image_url));

                            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"images\users\", uData.unique_id);

                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }

                            var i = Path.Combine(path, "profile.jpg");
                            if (!File.Exists(i))
                            {
                                img.Save(i);
                            }
                            else
                            {
                                File.Delete(i);
                                img.Save(i);
                            }
                            img.Dispose();
                            uData.profile_image   = uData.unique_id + "/profile.jpg";
                            db.Entry(uData).State = EntityState.Modified;
                            await db.SaveChangesAsync();

                            return("OK");
                        }
                        catch (HttpException ex)
                        {
                            await History.Create(History.Type.API, new History_API()
                            {
                                api_action   = "HttpException at ChangeUserPicture -->" + ex.Message + " | User -> name -" + user.display_name + ", guid - " + user.unique_id,
                                api_type     = "Exception thrown -> ChangeUserPicture",
                                api_datetime = DateTime.Now
                            });

                            return("Exception");
                        }
                    }
                    return("NotAuthorized");
                }