Пример #1
0
        //Get User
        public ReadUser GetUser(Guid id)
        {
            ApplicationUser user = ctx.Users.Find(id.ToString());

            if (user == null) //Check for a Null User
            {
                return(null);
            }
            if (user.CompanyID != _companyID) //Check that user is in the same company as the requesting user.
            {
                return(null);
            }

            ReadUser readUser = new ReadUser
            {
                UserID         = user.Id,
                CompanyID      = user.CompanyID,
                DepartmentID   = user.DepartmentID,
                Username       = user.UserName,
                Email          = user.Email,
                IsLocked       = user.LockoutEnabled,
                CreatedDateUTC = user.CreatedDateUTC
            };
            CreateHistory history = new CreateHistory
            {
                CompanyID = _companyID,
                UserID    = _userID.ToString(),
                Table     = "Users",
                stringID  = id.ToString(),
                Request   = $"GetUser({id})"
            };

            AddHistory(history);
            return(readUser);
        }
Пример #2
0
        public async Task <string> SaveOrUpdateUserAsync(ReadUserModel readUser, CancellationToken cancellationToken)
        {
            var existingRecord = await LoadUserByAggregateRootIdAsync(readUser.AggregateRootId, cancellationToken);

            if (existingRecord != null)
            {
                existingRecord.ChangeUserModel(readUser);
                await _databaseContext.SaveChangesAsync(cancellationToken);

                return(readUser.AggregateRootId);
            }

            try
            {
                var record = new ReadUser
                {
                    AggregateRootId = readUser.AggregateRootId,
                    FirstName       = readUser.FirstName,
                    LastName        = readUser.LastName,
                    UserName        = readUser.UserName,
                    Version         = readUser.Version + 1
                };

                await _databaseContext.ReadUsers.AddAsync(record, cancellationToken);

                await _databaseContext.SaveChangesAsync(cancellationToken);

                return(readUser.AggregateRootId);
            }
            catch
            {
                //TODO: add error handling
                return(null);
            }
        }
        private void DeleteUserPermissionAction(object obj)
        {
            ReadUserDTO user = (ReadUserDTO)obj;

            if (user != null && user.Username != ActiveUser.Instance.LoggedUser.Username)
            {
                ReadUser u = Users.FirstOrDefault(x => x.username == user.Username);

                if (u != null)
                {
                    Users.Remove(u);
                }
            }
        }
        public async void RemoveUserButtonClick(ReadUser user)
        {
            if (ActiveUser.IsActive == true)
            {
                bool succ = await PermissionService.DeletePermission(ActiveUser.Instance.LoggedUser.Token,
                                                                     parentBoardId, user.username);

                if (succ)
                {
                    ShowMessageBox(null, "Obrisan user");
                    ReadUser u = Users.FirstOrDefault(x => x.username == user.username);
                    Users.Remove(u);
                }
                else
                {
                    ShowMessageBox(null, "Error deleting user.");
                }
            }
            else
            {
                ShowMessageBox(null, "Error getting user.");
            }
        }
Пример #5
0
        public async Task <JsonResult> ChangePassword([FromBody] ChangePassword changePassword)
        {
            try
            {
                changePassword.Email = changePassword.Email.ToLower();

                if (!usersChangingPassword.ContainsKey(changePassword.Email))
                {
                    return(Json(new { Error = 1, Message = "Sorry we haven't found any request of changing password from this email. Please try again." }.ToJson()));
                }

                ReadUser myUser = null;
                usersChangingPassword.TryGetValue(changePassword.Email, out myUser);

                var users = _database.GetCollection <ReadUser>("users");

                if (myUser == null)
                {
                    return(Json(new { Error = 1, Message = "Sorry there has been a problem during changing your password" }.ToJson()));
                }

                String salt = String.Empty;
                myUser.Password = AuthHelper.EncryptPassword(changePassword.Password, out salt);

                var updatePasswordDefinition = Builders <ReadUser> .Update.Set("password", myUser.Password).Set("salt", salt);

                await users.UpdateOneAsync <ReadUser>(u => u.Email == changePassword.Email, updatePasswordDefinition);

                usersChangingPassword.Remove(myUser.Email);

                return(Json(new { Error = 0, Message = "Password Changed correctly" }.ToJson(jsonWriterSettings)));
            }
            catch (Exception ex)
            {
                return(Json(ex.RaiseException()));
            }
        }
 public bool CanRemoveUser(ReadUser user)
 {
     return(isAdmin && ActiveUser.IsActive == true &&
            ActiveUser.Instance.LoggedUser.Username != user.Username);
 }
Пример #7
0
 /// <summary>
 /// Check if User exists or not for given username and password
 /// </summary>
 /// <returns>bool</returns>
 public static UserData GetUser(string userName, string password)
 {
     return(ReadUser.ReadSpecificUserByUserName(userName, password));
 }
Пример #8
0
 /// <summary>This method return User object based on userID
 /// </summary>
 /// <param name="userID">int</param>
 /// <returns>User object</returns>
 public static UserData Specific(int userID)
 {
     return(ReadUser.ReadSpecificUser(userID));
 }