Пример #1
0
        public async Task <IActionResult> EditAsync([FromRoute] int profileId, [FromBody] UpdateProfileRequest model)
        {
            if (CurrentUser == null)
            {
                return(BadRequest(new { ErrorMessage = "Unauthorized" }));
            }

            var profile = await _profileService.GetProfile(profileId);

            if (!profile.Profile.UserId.Equals(CurrentUser.Id))
            {
                return(BadRequest(new { ErrorMessage = "You are not allowed to edit profile." }));
            }

            profile.Profile.User.Email       = model.Email;
            profile.Profile.User.FirstName   = model.FirstName;
            profile.Profile.User.LastName    = model.LastName;
            profile.Profile.User.PhoneNumber = model.PhoneNumber;
            profile.Profile.About            = model.About;
            _profileService.Update(profile.Profile);

            var editedProfile = await _profileService.GetProfile(profileId);

            return(Ok(_mapper.Map <ApplicationUserResponse>(editedProfile)));
        }
Пример #2
0
 public ProfileViewModel(UserItem user)
 {
     User      = user;
     Profile   = new UpdateProfileRequest();
     image     = new ImageItem();
     byteimage = new byte[4];
 }
Пример #3
0
        public async Task <Response <UpdateProfileResponse> > updateuser(UpdateProfileRequest request)
        {
            string userlogin = string.Empty;
            string token     = Request.Headers["Authorization"];

            // Get user login from token
            var info = this._authService.checkToken(token);
            Response <UpdateProfileResponse> response = new Response <UpdateProfileResponse>();
            UploadStatus statusUpload = new UploadStatus();

            if (!string.IsNullOrEmpty(info.Username))
            {
                if (request.File != null && request.File.Length > 0)
                {
                    statusUpload = await this.uploadFile(request.File, request.UserName + ".png");

                    if (statusUpload.Status)
                    {
                        return(await this._authService.updateUser(request, statusUpload.FileName));
                    }
                    response.message_type = 2;
                    response.message      = statusUpload.FileName;// Error upload file profile
                }
                return(await this._authService.updateUser(request, statusUpload.FileName));
            }
            else
            {
                response.message_type = 2;
                response.message      = "Unauthorize";
            }
            return(response);
        }
Пример #4
0
        public HttpResponseMessage Update([FromBody] UpdateProfileRequest request)
        {
            UserProfileManager profileMan = new UserProfileManager();
            var response = profileMan.UpdateUserProfile(request);

            return(response);
        }
Пример #5
0
        public async Task <ActionResult <UserResponse> > UpdateProfile([FromBody] UpdateProfileRequest request)
        {
            var login = User.Identity.Name;
            var users = await db.Users.AsNoTracking().ToListAsync();

            var user = users.Find(x => x.Login == login);

            if (user == null)
            {
                return(StatusCode(400, "There is not the user"));
            }

            var updatedUser = new User
            {
                Id       = user.Id,
                Login    = !string.IsNullOrEmpty(request.Login) ? request.Login : user.Login,
                Password = !string.IsNullOrEmpty(request.Password) ? request.Password : user.Password,
                Name     = request.Name,
                Surname  = request.Surname
            };

            db.Update(updatedUser);
            await db.SaveChangesAsync();

            return(new UserResponse {
                Name = updatedUser.Name, Surname = updatedUser.Surname
            });
        }
Пример #6
0
        public async Task <UpdateProfileResponse> UpdateProfile(UpdateProfileRequest request)
        {
            var response = new UpdateProfileResponse();
            var user     = await _sessionManager.GetUser();

            var dbRequest = new Repositories.DatabaseRepos.UserRepo.Models.UpdateUserRequest()
            {
                Id            = user.Id,
                Username      = request.Username,
                Email_Address = request.EmailAddress,
                First_Name    = request.FirstName,
                Last_Name     = request.LastName,
                Mobile_Number = request.MobileNumber,
                Updated_By    = user.Id
            };

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                await uow.UserRepo.UpdateUser(dbRequest);

                uow.Commit();
            }

            await _sessionManager.DehydrateSession(); // user has changed

            await _sessionManager.WriteSessionLogEvent(new Models.ManagerModels.Session.CreateSessionLogEventRequest()
            {
                EventKey = SessionEventKeys.UserUpdatedProfile,
            });

            response.Notifications.Add("Profile updated successfully", NotificationTypeEnum.Success);
            return(response);
        }
        public UpdateProfileResponse UpdateProfile(UpdateProfileRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            UpdateProfileResponse response = new UpdateProfileResponse();

            try
            {
                if (!CheckAuthDriver(request.user_id, request.auth_token))
                {
                    MakeNoDriverResponse(response);
                    return(response);
                }
                using (DriverDao dao = new DriverDao())
                {
                    Driver driver = dao.FindById(request.user_id);
                    driver.DriverName = request.driver_name;
                    //driver.MobileNumber = request.mobile_number;
                    //driver.ProfileImage = request.profile_image; //Commented bcz image is uploading as multipart
                    dao.Update(driver);
                    response.code         = 0;
                    response.has_resource = 0;
                    response.message      = MessagesSource.GetMessage("profile.changed");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
                return(response);
            }
        }
Пример #8
0
        public void Put(string id, UpdateProfileRequest body)
        {
            var areArgumentsValid = !string.IsNullOrEmpty(id) &&
                                    body != null &&
                                    !string.IsNullOrEmpty(body.Name);

            if (!areArgumentsValid)
            {
                return;
            }

            // HACK: Uncomment it when we done the authentication
            //var currentUserId = User.Identity.Name;
            //if (currentUserId != id) return;

            var userProfile        = _userProfileRepo.GetUserProfileById(id);
            var isUserProfileValid = userProfile != null && !userProfile.DeletedDate.HasValue;

            if (!isUserProfileValid)
            {
                return;
            }

            userProfile.Name             = body.Name;
            userProfile.SchoolName       = body.SchoolName;
            userProfile.IsPrivateAccount = body.IsPrivate;
            userProfile.CourseReminder   = body.IsReminderOnceTime ?
                                           UserProfile.ReminderFrequency.Once:
                                           UserProfile.ReminderFrequency.Twice;
            _userProfileRepo.UpsertUserProfile(userProfile);
        }
Пример #9
0
        public async Task <Response <UpdateProfileResponse> > updateProfile(UpdateProfileRequest request, string fileProfile)
        {
            Response <UpdateProfileResponse> response = new Response <UpdateProfileResponse>();

            try
            {
                if (!string.IsNullOrWhiteSpace(request.UserName))
                {
                    UserProfile user = await this._userManager.FindByNameAsync(request.UserName);

                    //if (string.IsNullOrWhiteSpace(user.ProfilePicture))
                    //{
                    if (!string.IsNullOrWhiteSpace(fileProfile))
                    {
                        user.ProfilePicture = fileProfile;
                    }
                    //}

                    user.FullName    = request.Namalengkap;
                    user.Email       = request.Email;
                    user.PhoneNumber = request.NoTelp;
                    this.Db.Users.Update(user);
                    this.Db.SaveChanges();
                }
            }
            catch (Exception exc) {
                response.message      = exc.Message;
                response.message_type = 2;
            }

            return(response);
        }
Пример #10
0
        public async Task Edit(string currentPassword = "",
            string username = null, string email = null, string password = null,
            Stream avatar = null, ImageType avatarType = ImageType.Png)
        {
            if (currentPassword == null) throw new ArgumentNullException(nameof(currentPassword));

            var request = new UpdateProfileRequest()
            {
                CurrentPassword = currentPassword,
                Email = email ?? Email,
                Password = password,
                Username = username ?? Client.PrivateUser.Name,
                AvatarBase64 = avatar.Base64(avatarType, Client.PrivateUser.AvatarId)
            };

            await Client.ClientAPI.Send(request).ConfigureAwait(false);

            if (password != null)
            {
                var loginRequest = new LoginRequest()
                {
                    Email = Email,
                    Password = password
                };
                var loginResponse = await Client.ClientAPI.Send(loginRequest).ConfigureAwait(false);
                Client.ClientAPI.Token = loginResponse.Token;
                Client.GatewaySocket.Token = loginResponse.Token;
                Client.GatewaySocket.SessionId = null;
            }
        }
Пример #11
0
        public ActionResult Edit(EditProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userService = new UserService();
                var user        = userService.GetUserByAccountId(new GetUserByAccountIdRequest()
                {
                    AccountId = User.Identity.GetUserId()
                }).User;

                if (user != null)
                {
                    var request = new UpdateProfileRequest
                    {
                        Id          = user.Id,
                        Description = model.Description,
                        Phone       = model.Phone,
                        FullName    = model.FullName,
                        ShowData    = model.ShowData
                    };

                    var response = userService.UpdateProfile(request);

                    return(RedirectToAction("Index", "Manage"));
                }
            }

            return(View(model));
        }
Пример #12
0
        public async Task UpdateProfileAsync2()
        {
            Mock <ProfileService.ProfileServiceClient> mockGrpcClient = new Mock <ProfileService.ProfileServiceClient>(MockBehavior.Strict);
            UpdateProfileRequest request = new UpdateProfileRequest
            {
                Profile = new Profile(),
            };
            Profile expectedResponse = new Profile
            {
                ProfileName    = new ProfileName("[PROJECT]", "[TENANT]", "[PROFILE]"),
                ExternalId     = "externalId-1153075697",
                Source         = "source-896505829",
                Uri            = "uri116076",
                GroupId        = "groupId506361563",
                Processed      = true,
                KeywordSnippet = "keywordSnippet1325317319",
            };

            mockGrpcClient.Setup(x => x.UpdateProfileAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Profile>(Task.FromResult(expectedResponse), null, null, null, null));
            ProfileServiceClient client = new ProfileServiceClientImpl(mockGrpcClient.Object, null);
            Profile response            = await client.UpdateProfileAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #13
0
        public UpdateProfileResponse UpdateProfile(UpdateProfileRequest request)
        {
            UpdateProfileResponse response = new UpdateProfileResponse();

            User user = _userRepository.Get(request.Id);

            if (user == null)
            {
                response.HasError = true;
                return(response);
            }

            user.Email     = request.UsersUpdateModel.Email;
            user.FirstName = request.UsersUpdateModel.FirstName;
            user.LastName  = request.UsersUpdateModel.LastName;

            // Security Questions
            foreach (var question in request.UsersUpdateModel.SecurityQuestions.Where(q => q.Answer.IsNotNullOrEmpty()))
            {
                user.UpdateQuestion(question.Id, question.Question, question.Answer);
            }

            _roleRepository.Query().Where(r => r.CustomerId == request.CustomerId).ToList().Map(
                request.UsersUpdateModel.SelectedRoles,
                r => r.AddUser(user),
                r => r.RemoveUser(user)
                );

            _unitOfWork.Commit();

            return(response);
        }
Пример #14
0
        public override async Task <UpdateProfileResponse> UpdateProfile(UpdateProfileRequest request, ServerCallContext context)
        {
            var updateProfileModel = new UpdateProfileModel
            {
                ProfileId     = Guid.Parse(request.ProfileId),
                FirstName     = request.FirstName,
                LastName      = request.LastName,
                PhotoThumbUrl = request.PhotoThumbUrl
            };

            var updateProfileCommand = new UpdateProfileCommand(updateProfileModel);

            var result = await _commandBus.TransactionSendAsync(updateProfileCommand);

            if (result.IsOk)
            {
                var response = result.Value as dynamic;

                return(new UpdateProfileResponse
                {
                    ProfileId = response.ProfileId,
                    FirstName = response.FirstName,
                    LastName = response.LastName,
                    PhotoThumbUrl = response.PhotoThumbUrl,
                });
            }

            var statusCode = (StatusCode)result.StatusCode;

            throw new RpcException(new Status(statusCode, result.Value?.ToString()));
        }
Пример #15
0
        public async Task <IActionResult> UpdateProfile(int profileId, UpdateProfileRequest request)
        {
            var cancellation = HttpContext.RequestAborted;

            var profile = await _dbContext.Profiles
                          .AsTracking()
                          .FirstOrDefaultAsync(p => p.Id == profileId, cancellation);

            if (profile == null)
            {
                return(Problem(
                           statusCode: 404,
                           title: "Not Found",
                           detail: $"Profile '{profileId}' not found"
                           ));
            }

            if (User.TryGetProfileId() != profileId)
            {
                return(Problem(
                           statusCode: 403,
                           title: "Forbidden",
                           detail: $"Profile '{profileId}' does not belong to the authenticated user"
                           ));
            }

            profile.IsPublic      = request.IsPublic;
            profile.Location      = request.Location;
            profile.Bio           = request.Bio;
            profile.ExternalLinks = request.ExternalLinks?.ToArray() ?? Array.Empty <string>();

            await _dbContext.SaveChangesAsync(cancellation);

            return(Ok());
        }
Пример #16
0
 public async void ChangeExpression(string face, string name)
 {
     face = face.ToLower();
     UpdateProfileRequest req = new UpdateProfileRequest();
     req.Username = name; //Give this your bots username if you leave it blank the name will  be None
     switch (face)
     {
         case "trump":
             req.AvatarBase64 = Faces.TrumpFace;
             break;
         case "hillary":
             req.AvatarBase64 = Faces.HillaryFace;
             break;
         case "resting":
             req.AvatarBase64 = Faces.RestingFace;
             break;
     }
     try
     {
         await _client.ClientAPI.Send(req);
     }
     catch(Exception e)
     {
         Console.WriteLine("[DISCORD API ERROR] "+e.Message);
     };
 }
        public void UpdateProfileRequestObject()
        {
            moq::Mock <ProfilerService.ProfilerServiceClient> mockGrpcClient = new moq::Mock <ProfilerService.ProfilerServiceClient>(moq::MockBehavior.Strict);
            UpdateProfileRequest request = new UpdateProfileRequest
            {
                Profile    = new Profile(),
                UpdateMask = new wkt::FieldMask(),
            };
            Profile expectedResponse = new Profile
            {
                Name         = "name1c9368b0",
                ProfileType  = ProfileType.Contention,
                Deployment   = new Deployment(),
                Duration     = new wkt::Duration(),
                ProfileBytes = proto::ByteString.CopyFromUtf8("profile_bytes12d9894a"),
                Labels       =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
            };

            mockGrpcClient.Setup(x => x.UpdateProfile(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            ProfilerServiceClient client = new ProfilerServiceClientImpl(mockGrpcClient.Object, null);
            Profile response             = client.UpdateProfile(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public async stt::Task UpdateProfileRequestObjectAsync()
        {
            moq::Mock <ProfilerService.ProfilerServiceClient> mockGrpcClient = new moq::Mock <ProfilerService.ProfilerServiceClient>(moq::MockBehavior.Strict);
            UpdateProfileRequest request = new UpdateProfileRequest
            {
                Profile    = new Profile(),
                UpdateMask = new wkt::FieldMask(),
            };
            Profile expectedResponse = new Profile
            {
                Name         = "name1c9368b0",
                ProfileType  = ProfileType.Contention,
                Deployment   = new Deployment(),
                Duration     = new wkt::Duration(),
                ProfileBytes = proto::ByteString.CopyFromUtf8("profile_bytes12d9894a"),
                Labels       =
                {
                    {
                        "key8a0b6e3c",
                        "value60c16320"
                    },
                },
            };

            mockGrpcClient.Setup(x => x.UpdateProfileAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Profile>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            ProfilerServiceClient client = new ProfilerServiceClientImpl(mockGrpcClient.Object, null);
            Profile responseCallSettings = await client.UpdateProfileAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Profile responseCancellationToken = await client.UpdateProfileAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public void UpdateProfile(UpdateProfileRequest request, Action <GuestControllerResult <ProfileResponse> > callback)
        {
            QueueItem item = CreateQueueItem("/client/{client-id}/guest/{swid}", HttpMethod.POST, request, GuestControllerAuthenticationType.AccessToken, callback);

            queue.Add(item);
            ExecuteNextCall();
        }
Пример #20
0
        public async Task Edit(string currentPassword = "",
                               string username        = null, string email         = null, string password = null,
                               Stream avatar          = null, ImageType avatarType = ImageType.Png)
        {
            if (currentPassword == null)
            {
                throw new ArgumentNullException(nameof(currentPassword));
            }

            var request = new UpdateProfileRequest()
            {
                CurrentPassword = currentPassword,
                Email           = email ?? Email,
                Password        = password,
                Username        = username ?? Client.PrivateUser.Name,
                AvatarBase64    = avatar.Base64(avatarType, Client.PrivateUser.AvatarId)
            };

            await Client.ClientAPI.Send(request).ConfigureAwait(false);

            if (password != null)
            {
                var loginRequest = new LoginRequest()
                {
                    Email    = Email,
                    Password = password
                };
                var loginResponse = await Client.ClientAPI.Send(loginRequest).ConfigureAwait(false);

                Client.ClientAPI.Token = loginResponse.Token;
            }
        }
Пример #21
0
        /*
         * Updates the profile of a staff
         */
        public ResponseErrorEnum?UpdateProfile(UpdateProfileRequest request)
        {
            try
            {
                var isEmailAlreadyUsed = _userRepository.Exists(s => s.Id != request.UserId && s.Email == request.Email);
                if (isEmailAlreadyUsed)
                {
                    return(ResponseErrorEnum.EmailAlreadyUsed);
                }

                var user = _userRepository.GetById(request.UserId);
                user.FirstName   = request.FirstName;
                user.LastName    = request.LastName;
                user.Email       = request.Email;
                user.PhoneNumber = request.PhoneNumber;
                user.Address     = request.Address;

                _userRepository.Update(user);
                _userRepository.Save();
            }
            catch
            {
                // TODO: Log the exception.
                return(ResponseErrorEnum.RepositoryError);
            }

            return(null);
        }
        public void UpdateProfile2()
        {
            Mock <ProfileService.ProfileServiceClient> mockGrpcClient = new Mock <ProfileService.ProfileServiceClient>(MockBehavior.Strict);
            UpdateProfileRequest request = new UpdateProfileRequest
            {
                Profile = new Profile(),
            };
            Profile expectedResponse = new Profile
            {
                ProfileName    = new ProfileName("[PROJECT]", "[TENANT]", "[PROFILE]"),
                ExternalId     = "externalId-1153075697",
                Source         = "source-896505829",
                Uri            = "uri116076",
                GroupId        = "groupId506361563",
                ResumeHrxml    = "resumeHrxml1834730555",
                Processed      = true,
                KeywordSnippet = "keywordSnippet1325317319",
            };

            mockGrpcClient.Setup(x => x.UpdateProfile(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            ProfileServiceClient client = new ProfileServiceClientImpl(mockGrpcClient.Object, null);
            Profile response            = client.UpdateProfile(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #23
0
        public UpdateProfileResponse UpdateProfile(UpdateProfileRequest request)
        {
            UpdateProfileResponse response = new UpdateProfileResponse();

            response.Errors = new List <BusinessRule>();

            User user = _repository
                        .FindBy(request.UserId);

            if (user != null)
            {
                try
                {
                    user.FirstName   = request.Firstname;
                    user.LastName    = request.Lastname;
                    user.PhoneNumber = request.PhoneNumber;
                    user.BirthDay    = request.BirthDay;
                    _repository.Save(user);
                    _uow.Commit();

                    response.Result = true;
                }
                catch (Exception ex)
                {
                    response.Errors.Add(new BusinessRule("Error", ex.Message));
                    response.Result = false;
                }
            }
            else
            {
                response.Result = false;
            }

            return(response);
        }
Пример #24
0
        public async Task <IActionResult> UpdateProfile(UpdateProfileRequest request)
        {
            var response = await mediator.Send(request);

            logger.LogResponse($"User #{HttpContext.GetCurrentUserId()} updated profile", response.Error);

            return(response.IsSucceeded ? (IActionResult)Ok(response) : BadRequest(response));
        }
        public async Task <IActionResult> UpdateProfile([FromBody] UpdateProfileRequest updateProfile)
        {
            var loggedUser = User.GetUserIdFromToken();
            var result     = await _accountService.UpdateProfileAsync(updateProfile, loggedUser);

            var user = _mapper.Map <UserResponse>(result);

            return(Ok(new ApiOkResponse(user)));
        }
Пример #26
0
        public async Task <IActionResult> UpdateProfile([FromBody] UpdateProfileRequest updateProfile)
        {
            var claimsIdentity = this.User.Identity as ClaimsIdentity;
            var userId         = claimsIdentity.FindFirst(ClaimTypes.UserData)?.Value;
            var result         = await _accountService.UpdateProfileAsync(updateProfile, int.Parse(userId));

            var user = _mapper.Map <UserResponse>(result);

            return(Ok(new ApiOkResponse(user)));
        }
Пример #27
0
        public async Task <IActionResult> UpdateUser([FromBody] UpdateProfileRequest request,
                                                     CancellationToken cancellationToken)
        {
            var command = UpdateProfileCommand.FromRequest(_currentUserId, request);
            var result  = await _mediator.Send(command, cancellationToken);

            return(result.IsSuccess
                ? Ok()
                : result.ReturnErrorResponse());
        }
Пример #28
0
        public void UpdateProfile(Identifier userId, UserProfileType profile)
        {
            UpdateProfileRequest request = new UpdateProfileRequest()
            {
                UserId      = userId,
                UserProfile = profile
            };

            CallWebService <IUserManagementServicev1_6, UpdateProfileRequest, UpdateProfileResponse>(
                m_service1_6, request, (s, q) => s.UpdateProfile(q));
        }
Пример #29
0
        public async Task <IActionResult> Update([FromBody] UpdateProfileRequest updateProfileRequest)
        {
            if (ModelState.IsValid)
            {
                var response = await _profileService.UpdateProfileAsync(updateProfileRequest.DisplayName,
                                                                        updateProfileRequest.Email, updateProfileRequest.Description, updateProfileRequest.GoogleId);

                return(response.Success ? new OkObjectResult(response.Data) : StatusCode(500));
            }
            return(StatusCode(500));
        }
Пример #30
0
        public async Task <ActionResult> UpdateProfile([FromBody] UpdateProfileRequest request)
        {
            var resp = await(await factory.GetAccountClientAsync())
                       .UpdateProfileAsync(new AcademyCloud.Identity.Protos.Account.UpdateProfileRequest()
            {
                Email = request.Email,
                Name  = request.Name,
            });

            return(NoContent());
        }
Пример #31
0
        public async Task Profile_UpdateSuccessful()
        {
            _output.WriteLine("Update profile of user: "******"api/profile", UriKind.Relative);
            StringContent content = new UpdateProfileRequest {
                DisplayName = "abc", Street = "Abc", City = "Abc", PostalCode = "3032"
            }.ToStringContent();
            HttpResponseMessage response = await _context.NewTestUserHttpClient.PatchAsync(url, content);

            response.EnsureSuccessStatusCode();
        }