Пример #1
0
        public override void Execute()
        {
            ICollection <IUser> users = this.Forum.Users;

            string username = this.Data[1];
            string password = PasswordUtility.Hash(this.Data[2]);

            if (this.Forum.IsLogged)
            {
                throw new CommandException(Messages.AlreadyLoggedIn);
            }

            IUser user = (User)users.First(u => u.Username == username && u.Password == password);

            if (user == null)
            {
                throw new CommandException(Messages.InvalidLoginDetails);
            }

            this.Forum.CurrentUser = user;

            StringBuilder loginResult = new StringBuilder();

            loginResult.AppendFormat(Messages.LoginSuccess, username);
            this.Forum.Output.AppendLine(loginResult.ToString());
        }
Пример #2
0
        public override void Execute()
        {
            this.Forum.CurrentQuestion = null;

            var    users    = this.Forum.Users;
            string username = this.Data[1];
            string password = this.Data[2];

            if (this.Forum.IsLogged)
            {
                this.Forum.Output.AppendLine(string.Format(Messages.AlreadyLoggedIn));
            }
            else
            {
                var foundUser = false;
                foreach (var user in users)
                {
                    if (user.Username == username &&
                        user.Password == PasswordUtility.Hash(password))
                    {
                        this.Forum.CurrentUser = user;
                        this.Forum.Output.AppendLine(string.Format(Messages.LoginSuccess, username));
                        foundUser = true;
                    }
                }

                if (!foundUser)
                {
                    throw new CommandException(Messages.InvalidLoginDetails);
                }
            }
        }
Пример #3
0
        public override void Execute()
        {
            if (this.Forum.CurrentUser != null)
            {
                this.Forum.Output.AppendLine(
                    string.Format(Messages.AlreadyLoggedIn));
                return;
            }

            var    users    = this.Forum.Users.ToList();
            string username = this.Data[1];
            string password = PasswordUtility.Hash(this.Data[2]);
            var    user     = users.Single(u => u.Username == username);

            if (user == null || user.Password != password)
            {
                this.Forum.Output.AppendLine(
                    string.Format(Messages.InvalidLoginDetails));
                return;
            }

            this.Forum.CurrentUser = user;
            this.Forum.Output.AppendLine(
                string.Format(Messages.LoginSuccess, username));
        }
Пример #4
0
        public override void Execute()
        {
            var    users    = this.Forum.Users;
            string username = this.Data[1];
            string password = PasswordUtility.Hash(this.Data[2]);
            string email    = this.Data[3];

            if (users.Any(u => u.Username == username || u.Email == email))
            {
                throw new CommandException(Messages.UserAlreadyRegistered);
            }

            IUser user;

            if (this.Data.Count > 4)
            {
                var role = this.Data[4];

                switch (role.ToLower())
                {
                case "administrator":
                    if (users.Any())
                    {
                        throw new CommandException(Messages.RegAdminNotAllowed);
                    }

                    user = new Administrator(users.Count + 1, username, password, email);

                    // TODO: Implement administrator
                    //throw new NotImplementedException();
                    break;

                default:
                    user = new User(users.Count + 1, username, password, email);
                    break;
                }
            }
            else
            {
                user = new User(users.Count + 1, username, password, email);
            }

            users.Add(user);

            this.Forum.Output.AppendLine(
                string.Format(Messages.RegisterSuccess, username, users.Last().Id)
                );
        }
Пример #5
0
        public override void Execute()
        {
            ICollection <IUser> users = this.Forum.Users;
            string username           = this.Data[1];
            string password           = PasswordUtility.Hash(this.Data[2]);
            string email = this.Data[3];

            if (users.Any(u => u.Username == username || u.Email == email))
            {
                throw new CommandException(Messages.UserAlreadyRegistered);
            }

            User user;

            if (this.Data.Count > 4)
            {
                string role = this.Data[4];

                switch (role.ToLower())
                {
                case "administrator":
                    if (users.Any())
                    {
                        throw new CommandException(Messages.RegAdminNotAllowed);
                    }

                    user = new Administrator(users.Count + 1, username, password, email);
                    break;

                default:
                    user = new User(users.Count + 1, username, password, email);
                    break;
                }
            }
            else
            {
                user = new User(users.Count + 1, username, password, email);
            }

            users.Add(user);

            StringBuilder registerCommand = new StringBuilder();

            registerCommand.AppendFormat(Messages.RegisterSuccess, username, users.Last().Id);
            this.Forum.Output.AppendLine(registerCommand.ToString());
        }
Пример #6
0
        public override void Execute()
        {
            var    users    = this.Forum.Users;
            string username = this.Data[1];
            string password = PasswordUtility.Hash(this.Data[2]);

            if (this.Forum.IsLogged)
            {
                throw new CommandException(Messages.AlreadyLoggedIn);
            }
            if (users.Where(u => u.Username == username && u.Password == password).Count() == 0)
            {
                throw new CommandException(Messages.InvalidLoginDetails);
            }
            this.Forum.CurrentUser = users.Where(u => u.Username == username && u.Password == password).FirstOrDefault();
            this.Forum.Output.AppendLine(string.Format(Messages.LoginSuccess, this.Forum.CurrentUser.Username));
        }
Пример #7
0
        public override void Execute()
        {
            var username    = this.Data[1];
            var password    = PasswordUtility.Hash(this.Data[2]);
            var currentUser = this.Forum.Users.FirstOrDefault(u => u.Username == username && u.Password == password);

            if (currentUser == null)
            {
                throw new CommandException(Messages.InvalidLoginDetails);
            }
            if (this.Forum.CurrentUser == currentUser)
            {
                throw new CommandException(Messages.AlreadyLoggedIn);
            }

            this.Forum.CurrentUser = currentUser;
            this.Forum.Output.AppendFormat(Messages.LoginSuccess, this.Forum.CurrentUser.Username).AppendLine();
        }
Пример #8
0
        public override void Execute()
        {
            if (this.Forum.IsLogged)
            {
                throw new CommandException(Messages.AlreadyLoggedIn);
            }

            string username = this.Data[1];
            string password = PasswordUtility.Hash(this.Data[2]);

            IUser user = this.Forum.Users
                         .FirstOrDefault(u => u.Username == username);

            if (user == null || user.Password != password)
            {
                throw new CommandException(Messages.InvalidLoginDetails);
            }

            this.Forum.CurrentUser = user;

            this.Forum.Output.AppendLine(
                string.Format(Messages.LoginSuccess, username));
        }
Пример #9
0
        public override void Execute()
        {
            if (this.Forum.IsLogged)
            {
                throw new CommandException(Messages.AlreadyLoggedIn);
            }

            var    users    = this.Forum.Users;
            string username = this.Data[1];
            string password = PasswordUtility.Hash(this.Data[2]);
            IUser  currentUser;

            if (users.Count == 0)
            {
                throw new CommandException(Messages.InvalidLoginDetails);
            }

            try
            {
                currentUser = users.First(x => string.Compare(x.Username, username, false) == 0);
            }
            catch (InvalidOperationException)
            {
                throw new CommandException(Messages.InvalidLoginDetails);
            }

            if (currentUser.Password != password)
            {
                throw new CommandException(Messages.InvalidLoginDetails);
            }

            this.Forum.CurrentUser = currentUser;

            this.Forum.Output.AppendLine(
                string.Format(Messages.LoginSuccess, username));
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new GPnaviServerContext(serviceProvider.GetRequiredService <DbContextOptions <GPnaviServerContext> >()))
            {
                bool isDirty = false;

                if (!context.UserMasters.Any())
                {
                    // 担当者マスタの初期設定
                    context.UserMasters.AddRange(
                        new UserMaster
                    {
                        LoginId   = "999",
                        Password  = PasswordUtility.Hash("999"),
                        LoginName = "初期設定管理者",
                        Role      = ApiConstant.ROLE_ADMIN,
                        IsValid   = true,
                    },
                        new UserMaster
                    {
                        LoginId   = "111",
                        Password  = PasswordUtility.Hash("1234"),
                        LoginName = "山田太郎",
                        Role      = ApiConstant.ROLE_WORK,
                        IsValid   = true,
                    },
                        new UserMaster
                    {
                        LoginId   = "222",
                        Password  = PasswordUtility.Hash("5678"),
                        LoginName = "鈴木次郎",
                        Role      = ApiConstant.ROLE_WORK,
                        IsValid   = true,
                    },
                        new UserMaster
                    {
                        LoginId   = "333",
                        Password  = PasswordUtility.Hash("0000"),
                        LoginName = "佐藤三郎",
                        Role      = ApiConstant.ROLE_WORK,
                        IsValid   = true,
                    }
                        );

                    isDirty = true;
                }

                if (!context.WorkScheduleMasters.Any())
                {
                    // WSマスタの初期設定
                    context.WorkScheduleMasters.AddRange(
                        new WorkScheduleMaster
                    {
                        Version   = 0,
                        Start     = "7:00",
                        Name      = "チルド2便納品",
                        ShortName = "チルド納品",
                        Priority  = "H",
                        IconId    = "0003",
                        Time      = "30",
                        Holiday   = "0",
                        Row       = 1
                    },
                        new WorkScheduleMaster
                    {
                        Version   = 0,
                        Start     = "7:00",
                        Name      = "ヤマザキ2便検収・納品",
                        ShortName = "ヤマザキ検収・納品",
                        Priority  = "H",
                        IconId    = "0003",
                        Time      = "30",
                        Holiday   = "0",
                        Row       = 2
                    },
                        new WorkScheduleMaster
                    {
                        Version   = 0,
                        Start     = "7:00",
                        Name      = "店頭ガラス清掃",
                        ShortName = "ガラス清掃",
                        Priority  = "L",
                        IconId    = "0008",
                        Time      = "15",
                        Holiday   = "0",
                        Row       = 3
                    },
                        new WorkScheduleMaster
                    {
                        Version   = 0,
                        Start     = "7:00",
                        Name      = "入口ドア清掃",
                        ShortName = "ドア清掃",
                        Priority  = "L",
                        IconId    = "0008",
                        Time      = "10",
                        Holiday   = "0",
                        Row       = 4
                    },
                        new WorkScheduleMaster
                    {
                        Version   = 0,
                        Start     = "7:00",
                        Name      = "チルド2便納品",
                        ShortName = "チルド納品",
                        Priority  = "H",
                        IconId    = "0003",
                        Time      = "30",
                        Holiday   = "1",
                        Row       = 5
                    },
                        new WorkScheduleMaster
                    {
                        Version   = 0,
                        Start     = "7:00",
                        Name      = "雑誌検収・納品",
                        ShortName = "検収・納品",
                        Priority  = "M",
                        IconId    = "0003",
                        Time      = "15",
                        Holiday   = "1",
                        Row       = 6
                    },
                        new WorkScheduleMaster
                    {
                        Version   = 0,
                        Start     = "7:00",
                        Name      = "入口ドア清掃",
                        ShortName = "ドア清掃",
                        Priority  = "L",
                        IconId    = "0008",
                        Time      = "10",
                        Holiday   = "1",
                        Row       = 7
                    }
                        );

                    isDirty = true;
                }

                if (!context.HolidayMasters.Any())
                {
                    // 休日マスタの初期設定
                    context.HolidayMasters.AddRange(
                        new HolidayMaster
                    {
                        Holiday = new DateTime(2018, 9, 17)
                    },
                        new HolidayMaster
                    {
                        Holiday = new DateTime(2018, 9, 23)
                    },
                        new HolidayMaster
                    {
                        Holiday = new DateTime(2018, 10, 8)
                    },
                        new HolidayMaster
                    {
                        Holiday = new DateTime(2018, 11, 3)
                    },
                        new HolidayMaster
                    {
                        Holiday = new DateTime(2018, 11, 23)
                    },
                        new HolidayMaster
                    {
                        Holiday = new DateTime(2018, 12, 23)
                    }
                        );

                    isDirty = true;
                }

                if (!context.SensorMasters.Any())
                {
                    // センサーマスタの初期設定
                    context.SensorMasters.AddRange(
                        new SensorMaster
                    {
                        SensorId    = "9001",
                        SensorType  = ApiConstant.SENSOR_TYPE_POT,
                        DisplayName = "ポット1"
                    },
                        new SensorMaster
                    {
                        SensorId    = "9002",
                        SensorType  = ApiConstant.SENSOR_TYPE_POT,
                        DisplayName = "ポット2"
                    },
                        new SensorMaster
                    {
                        SensorId    = "9003",
                        SensorType  = ApiConstant.SENSOR_TYPE_TRASH,
                        DisplayName = "ごみ箱1"
                    },
                        new SensorMaster
                    {
                        SensorId    = "9004",
                        SensorType  = ApiConstant.SENSOR_TYPE_TRASH,
                        DisplayName = "ごみ箱2"
                    }
                        );

                    isDirty = true;
                }

                if (isDirty)
                {
                    context.SaveChanges();
                }
            }
        }