Example #1
0
        public void AddUserInfo(CreateUserInfoRequest request, ApplicationUser user)
        {
            _databaseContext.UserInfo.Add(
                new UserInfo
            {
                Id             = Guid.NewGuid().ToString(),
                Latitude       = request.Latitude,
                Longitude      = request.Longitude,
                UserId         = user.Id,
                MessagingToken = request.MessagingToken
            });

            _databaseContext.SaveChanges();
        }
Example #2
0
        public async Task <IActionResult> Add([FromBody] CreateUserInfoRequest request)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    _userInfoService.AddUserInfo(request, user);
                    _logger.LogInformation(1, "User info created.");

                    return(new ObjectResult("User info created."));
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }
            }

            return(new ObjectResult("Error"));
        }
Example #3
0
        public CreateUserInfoResponse Process(CreateUserInfoRequest request)
        {
            try
            {
                if (request.UserInfo == null)
                {
                }

                var userEnrollInfoDao = new UserEnrollInfoDao();
                var userDao           = new UserInfoDao();

                var enroll = new Enroll()
                {
                    DIN = (UInt64)request.UserInfo.UserId, Fingerprint = new byte[Zd2911Utils.MaxFingerprintLength * 10]
                };
                var deviceUser = new User()
                {
                    DIN = (UInt64)request.UserInfo.UserId, Enrolls = new List <Enroll> {
                        enroll
                    }
                };

                UserInfoMapper.UpdateSystemInfo(ref deviceUser, request.UserInfo);
                bool result = userDao.SaveOrUpdateUser(deviceUser);

                return(new CreateUserInfoResponse()
                {
                    Token = request.Token, ResultType = ResultType.OK
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(new CreateUserInfoResponse()
                {
                    Token = request.Token, ResultType = ResultType.Error
                });
            }
        }
Example #4
0
        public void AddUser(User user, DeviceController device)
        {
            if (user == null || device == null)
            {
                return;
            }
            if (user.UserAuthentications == null || user.UserAuthentications.Count == 0)
            {
                return;
            }
            if (user.GetUserAccessableDeviceIds().Contains(device.DeviceID) == false)
            {
                return;
            }

            var deviceID   = device.DeviceID;
            var deviceCode = device.Code.ToInt32();

            Log.Info("Getting user authentication infos...");
            var userAuthenticationsOfDevice = user.UserAuthentications.Where(a => a.DeviceID == deviceID);
            var authenticationsOfDevice     = userAuthenticationsOfDevice as IList <UserAuthentication> ?? userAuthenticationsOfDevice.ToList();

            Log.Info("Getting user permission infos...");
            var deviceRoles = _deviceRole.Query(new Hashtable {
                { "Status", (int)GeneralStatus.Enabled }
            }).ToList();
            var userDevicePermission = user.GetUserDeviceRoleAuthorizedPermissionByDeviceId(deviceID, deviceRoles);

            Log.Info("Building device user...");
            var deviceUser = new UserInfo();

            deviceUser.UserId           = user.UserCode.ToInt32();
            deviceUser.ExternalUserCode = user.UserID.ToString();
            // user info
            deviceUser.UserName     = user.Name;
            deviceUser.UserStatus   = user.Status == GeneralStatus.Enabled;
            deviceUser.DepartmentId = user.DepartmentID;
            deviceUser.Comment      = user.Remark;
            // user role
            deviceUser.Role             = (Rld.DeviceSystem.Contract.Model.UserRole)userDevicePermission.PermissionAction.GetHashCode();
            deviceUser.AccessTimeZoneId = userDevicePermission.AllowedAccessTimeZoneID;

            //user authentication
            foreach (var userAuthentication in authenticationsOfDevice)
            {
                switch (userAuthentication.AuthenticationType)
                {
                case AuthenticationType.FingerPrint1:
                case AuthenticationType.FingerPrint2:
                case AuthenticationType.FingerPrint3:
                case AuthenticationType.FingerPrint4:
                case AuthenticationType.FingerPrint5:
                case AuthenticationType.FingerPrint6:
                case AuthenticationType.FingerPrint7:
                case AuthenticationType.FingerPrint8:
                case AuthenticationType.FingerPrint9:
                case AuthenticationType.FingerPrint10:
                {
                    var service = new FingerPrintService()
                    {
                        Index = (int)userAuthentication.AuthenticationType, Enabled = true
                    };
                    service.FingerPrintData = userAuthentication.AuthenticationData;
                    service.UseForDuress    = userAuthentication.IsDuress;
                    deviceUser.CredentialServices.Add(service);
                }
                break;

                case AuthenticationType.Password:
                {
                    var service = new PasswordService()
                    {
                        Enabled = true
                    };
                    service.Password     = SimpleEncryption.Decode(userAuthentication.AuthenticationData);
                    service.UseForDuress = userAuthentication.IsDuress;
                    deviceUser.CredentialServices.Add(service);
                }
                break;

                case AuthenticationType.IcCard:
                {
                    var service = new CredentialCardService()
                    {
                        Enabled = true
                    };
                    service.CardNumber   = userAuthentication.AuthenticationData;
                    service.UseForDuress = userAuthentication.IsDuress;
                    deviceUser.CredentialServices.Add(service);
                }
                break;

                default:
                    break;
                }
            }

            Log.Info("Invoke WebSocketOperation...");
            var operation             = new WebSocketOperation(deviceCode);
            var createUserInfoRequest = new CreateUserInfoRequest()
            {
                Token = operation.Token, UserInfo = deviceUser
            };
            string rawRequest  = DataContractSerializationHelper.Serialize(createUserInfoRequest);
            var    rawResponse = operation.Execute(rawRequest);

            if (string.IsNullOrWhiteSpace(rawResponse))
            {
                throw new Exception(string.Format("Create user id:[{0}], device user id:[{1}] to device id:[{2}] fails. Response is empty, maybe the device is not register to device system.",
                                                  user.UserID, deviceUser.UserId, deviceID));
            }

            var response = DataContractSerializationHelper.Deserialize <CreateUserInfoResponse>(rawResponse);

            Log.InfoFormat("Create user id:[{0}], device user id:[{1}] to device id:[{2}], result:[{3}]", user.UserID, deviceUser.UserId, deviceID, response.ResultType);

            if (response.ResultType != ResultType.OK)
            {
                throw new Exception(string.Format("Create user id:[{0}], device user id:[{1}] to device id:[{2}] fails.", user.UserID, deviceUser.UserId, deviceID));
            }
        }
Example #5
0
        private void AddUserMS(User user, DeviceController deviceInfo, DeviceRole role)
        {
            var deviceId             = deviceInfo.DeviceID;
            var tryGetAuthentication = user.UserAuthentications.FirstOrDefault(x => x.DeviceID != deviceId);

            if (tryGetAuthentication != null)
            {
                var otherDeviceId = tryGetAuthentication.DeviceID;
                var otherdeviceAuthentications = user.UserAuthentications.FindAll(x => x.DeviceID == otherDeviceId);

                var devicePermission = role.DeviceRolePermissions.FirstOrDefault(x => x.DeviceID == deviceId);

                Log.Info("Building device user...");
                var deviceUser = new UserInfo();
                deviceUser.UserId           = tryGetAuthentication.DeviceUserID; // don't know how to determine new the device user id
                deviceUser.ExternalUserCode = user.UserID.ToString();
                deviceUser.UserName         = user.Name;
                deviceUser.UserStatus       = user.Status == GeneralStatus.Enabled;
                deviceUser.DepartmentId     = user.DepartmentID;
                deviceUser.Comment          = user.Remark;
                deviceUser.Role             = (Rld.DeviceSystem.Contract.Model.UserRole)devicePermission.PermissionAction.GetHashCode();
                deviceUser.AccessTimeZoneId = devicePermission.AllowedAccessTimeZoneID;

                foreach (AuthenticationType type in Enum.GetValues(typeof(AuthenticationType)))
                {
                    switch (type)
                    {
                    case AuthenticationType.FingerPrint1:
                    case AuthenticationType.FingerPrint2:
                    case AuthenticationType.FingerPrint3:
                    case AuthenticationType.FingerPrint4:
                    case AuthenticationType.FingerPrint5:
                    case AuthenticationType.FingerPrint6:
                    case AuthenticationType.FingerPrint7:
                    case AuthenticationType.FingerPrint8:
                    case AuthenticationType.FingerPrint9:
                    case AuthenticationType.FingerPrint10:
                    {
                        var service = new FingerPrintService()
                        {
                            Index = (int)type, Enabled = false
                        };

                        var userAuthentication = otherdeviceAuthentications.FirstOrDefault(a => a.AuthenticationType == type);
                        if (userAuthentication != null)
                        {
                            service.Enabled         = true;
                            service.FingerPrintData = userAuthentication.AuthenticationData;
                            service.UseForDuress    = userAuthentication.IsDuress;
                        }

                        deviceUser.CredentialServices.Add(service);
                    }
                    break;

                    case AuthenticationType.Password:
                    {
                        var service = new PasswordService()
                        {
                            Enabled = false
                        };

                        var userAuthentication = otherdeviceAuthentications.FirstOrDefault(a => a.AuthenticationType == type);
                        if (userAuthentication != null)
                        {
                            service.Enabled      = true;
                            service.Password     = userAuthentication.AuthenticationData;
                            service.UseForDuress = userAuthentication.IsDuress;
                        }

                        deviceUser.CredentialServices.Add(service);
                    }
                    break;

                    case AuthenticationType.IcCard:
                    {
                        var service = new CredentialCardService()
                        {
                            Enabled = false
                        };

                        var userAuthentication = otherdeviceAuthentications.FirstOrDefault(a => a.AuthenticationType == type);
                        if (userAuthentication != null)
                        {
                            service.Enabled      = true;
                            service.CardNumber   = userAuthentication.AuthenticationData;
                            service.UseForDuress = userAuthentication.IsDuress;
                        }

                        deviceUser.CredentialServices.Add(service);
                    }
                    break;

                    //case AuthenticationType.FacePrint:
                    //    break;
                    default:
                        break;
                    }
                }

                Log.Info("Invoke WebSocketOperation...");
                var operation             = new WebSocketOperation(deviceId);
                var createUserInfoRequest = new CreateUserInfoRequest()
                {
                    Token = operation.Token, UserInfo = deviceUser
                };
                string rawRequest = DataContractSerializationHelper.Serialize(createUserInfoRequest);

                Log.DebugFormat("Request: {0}", rawRequest);
                var rawResponse = operation.Execute(rawRequest);
                Log.DebugFormat("Response: {0}", rawResponse);

                var response = DataContractSerializationHelper.Deserialize <UpdateUserInfoResponse>(rawResponse);
                Log.InfoFormat("Update user id:[{0}], device user id:[{1}] to device id:[{2}], result:[{3}]", user.UserID, deviceUser.UserId, deviceId, response.ResultType);

                if (response.ResultType != ResultType.OK)
                {
                    throw new Exception(string.Format("Update user id:[{0}], device user id:[{1}] to device id:[{2}] fails]", user.UserID, deviceUser.UserId, deviceId));
                }

                Log.Info("Adding UserAuthentications from database...");
                foreach (var au in otherdeviceAuthentications)
                {
                    var a = au.WiseClone();
                    a.DeviceID     = deviceId;
                    a.CreateDate   = DateTime.Now;
                    a.CreateUserID = SyncUserID;

                    _userAuthenticationRepo.Insert(a);
                }
            }
        }