public void ShouldGenerateAvatarWithSpacedColors()
        {
            var ag = new AvatarGenerator(
                new SpacedColorGenerator {
                Accuracy = 50
            }
                )
            {
                ImageFormat = ImageFormat.Png
            };

            var imageList = new List <string>();

            for (var i = 0; i < 25; i++)
            {
                var stream     = ag.Generate("Hello", "World");
                var base64Data = Convert.ToBase64String(stream.ToArray());

                var imgTag = $"<img src='data:image/png;base64,{base64Data}' />";
                imageList.Add(imgTag);
            }

            var images = string.Join("<br/>", imageList);

            Assert.IsFalse(string.IsNullOrEmpty(images));
        }
Beispiel #2
0
        public API_Response <UserAvatar> UploadAvatar([FromUri] long UserID, [FromUri] string api_key = "")
        {
            return(InvokeAPI(() =>
            {
                if (!Global.Cache.CheckUserExists(UserID))
                {
                    throw new UserNotFoundException();
                }
                //
                var httpRequest = System.Web.HttpContext.Current.Request;
                if (httpRequest.Files.Count == 0)
                {
                    throw new Exception("Image not found");
                }
                else
                {
                    var file = httpRequest.Files[0];
                    switch (System.IO.Path.GetExtension(file.FileName).ToLower())
                    {
                    case ".jpg":
                    case ".png":
                    case ".jpeg":
                    case ".gif":
                        return AvatarGenerator.Generate(file.InputStream, UserID);

                    default: throw new Exception("Incorrect format");;
                    }
                }
            }, api_key));
        }
        public ActionResult LoginByFacebook(UserLoginByFacebookDTO userLoginDTO)
        {
            if (IsUserLogIn)
            {
                return(RedirectToAction("Index", "Desktop"));
            }
            if (!userLoginDTO.Validate())
            {
                return(RedirectToAction("Registration", "Errors"));
            }
            // get user
            var user = _DL.User.Get.ByExternalID(userLoginDTO.ExternalID, EN_RegistrationSource.Facebook);

            // login
            if (user != null)
            {
                CurrentUser = user;
                return(RedirectToAction("Index", "Desktop"));
            }
            // register
            else
            {
                VM_UserRegister regUser = userLoginDTO.TO_VM();
                regUser.InvitedBy        = _DL.User.Get.SystemUser();
                regUser.UserLoginDetails = new Security.Salted_Hash();
                var userNew = _DL.User.Account.Register(regUser);
                CurrentUser = _DL.User.Get.ByID(userNew.UserID);
                // Get avatars
                System.Net.WebClient client = new System.Net.WebClient();
                Stream avatatLarge          = client.OpenRead(userLoginDTO.PictureLarge);
                // replace avatars
                AvatarGenerator.Generate(avatatLarge, CurrentUser.UserID);
                return(RedirectToAction("Index", "Desktop"));
            }
        }
Beispiel #4
0
        public override Task <IdentityResult> CreateAsync(User user, string password)
        {
            var generator = new AvatarGenerator();

            user.Avatar = generator.Generate(user.UserName);

            return(base.CreateAsync(user, password));
        }
        public void ShouldGenerateAvatar()
        {
            var ag = new AvatarGenerator(new PaletteColorGenerator()) {ImageFormat = ImageFormat.Png};
            var imageList = new List<string>();
            for (int i = 0; i < 25; i++)
            {
                var stream = ag.Generate("Hello", "World");
                var base64Data = Convert.ToBase64String(stream.ToArray());

                var imgTag = $"<img src='data:image/png;base64,{base64Data}' />";
                imageList.Add(imgTag);
            }

            var images = string.Join("<br/>", imageList);

            Assert.IsFalse(string.IsNullOrEmpty(images));
        }
        public JsonResult Upload(HttpPostedFileBase avatar)
        {
            if (avatar != null)
            {
                switch (Path.GetExtension(avatar.FileName).ToLower())
                {
                case ".jpg":
                case ".png":
                case ".jpeg":
                case ".gif":
                case ".tiff":
                    return(GetJson(AvatarGenerator.Generate(avatar.InputStream, CurrentUser.UserID)));

                default: return(GetJson(EN_ErrorCodes.IncorrectFileType));
                }
            }
            else
            {
                return(GetJson(EN_ErrorCodes.NoData));
            }
        }