예제 #1
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            
            var user = new User() { UserName = model.Username, Email = model.Email, RegistrationDate = DateTime.Now, LatestActivityDate = DateTime.Now };

            if (model.LocalAvatarPath != null)
            {
                var dropboxConnection = new DropboxConnection();
                dropboxConnection.UploadNewUserAvatar(model.LocalAvatarPath, user.UserName);

                user.AvatarUrl = dropboxConnection.GetShareableLink(model.LocalAvatarPath);
            }

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }
예제 #2
0
        public IHttpActionResult ChangeAvatar(string avatarLocationUrl)
        {
            if (avatarLocationUrl == null)
            {
                return BadRequest("No avatar link provided");
            }

            var userId = User.Identity.GetUserId();
            if (data == null)
            {
                data = new CodeChestData(new CodeChestDbContext());
            }

            var user = data.Users.All().FirstOrDefault(u => u.Id == userId);
            if (user == null)
            {
                return BadRequest("You must be logged in to change your avatar.");                
            }

            var dropboxConnection = new DropboxConnection();
            dropboxConnection.UploadNewUserAvatar(avatarLocationUrl, user.UserName);

            user.AvatarUrl = dropboxConnection.GetShareableLink(avatarLocationUrl);
            data.SaveChanges();

            return Ok();
        }