예제 #1
0
 /// <summary>
 /// check if retyped password match the first inserted
 /// </summary>
 /// <param name="msg"></param>
 protected void handleWaitForConfirm(string msg)
 {
     if (password == msg)
     {
         using (bbsContext bbs = new bbsContext())
         {
             user = bbs.GetUserByUsername(user.Userid);
             user.SetPassword(password);
             bbs.SaveChanges();
         }
         EventLogger.Write(
             string.Format("Password changed successfully for user '{0}'", user.Userid), client.Remote);
         LnWrite(catalog.GetString("Password changed successfully."));
         Writeln();
         client.inputMode = EInputMode.LineMode;
         client.status    = EClientStatus.LoggedIn;
         status           = states.WaitForContinue;
     }
     else
     {
         LnWrite(catalog.GetString("The two passwords do not match."));
         LnWrite(catalog.GetString("New password") + ": ");
         status = states.WaitForNewPassword;
     }
 }
예제 #2
0
        /// <summary>
        /// Fills the messages area list
        /// </summary>
        protected override void AddList()
        {
            if (Params.Length < 2)
            {
                return;                     // There is no area filter
            }
            string area   = Params[1].Trim().ToUpper();
            string filter = Params.Length > 2 ? Params[2].Trim().ToUpper() : string.Empty;
            string fmt    = "{0,5} {1,1} {2,1} {3,-30} {4}";

            using (bbsContext bbs = new bbsContext())
            {
                User           user = bbs.GetUserByUsername(client.username);
                List <Message> list = bbs.GetAllMessagesInArea(area).ToList();
                foreach (Message m in list)
                {
                    Text.Add(TextHelper.Truncate(string.Format(fmt, new object[]
                    {
                        m.Id, m.IsNew(user.LastLoginDate) ? "N" : "", m.IsRead(client.username) ? "" : "U",
                        TextHelper.Truncate(m.MessageFrom, 30), m.Subject
                    }), client.screenWidth));

                    Data.Actions.Add(m.Id.ToString(), new Parser.BBSCodeResult.Action()
                    {
                        module = "MessageScreen",
                        data   = string.Format("@MessageScreen;{0}", m.Id)
                    });
                }
            }
            KeyLength = 5;
        }
예제 #3
0
 /// <summary>
 /// Complete constructor
 /// </summary>
 /// <param name="c">Client reference</param>
 /// <param name="s">Server reference</param>
 /// <param name="text">Text to parse and optional parameters separated by semicolon</param>
 /// <param name="prev">Link to caller screen</param>
 public ChangePassword(IBBSClient c, IServer s, string text, IScreen prev) : base(c, s, text, prev)
 {
     status = states.WaitForOldPassword;
     using (bbsContext bbs = new bbsContext())
         user = bbs.GetUserByUsername(client.username);
     InitCatalog();
 }
예제 #4
0
        /// <summary>
        /// Fills the messages area list
        /// </summary>
        protected override void AddList()
        {
            string fmt = "{0,-20} {1,4} {2,4} {3,4} {4}";

            using (bbsContext bbs = new bbsContext())
            {
                User user = bbs.GetUserByUsername(client.username);
                List <MessageArea> list = bbs.GetMessageAllowedAreasByGroup(
                    Params.Length > 1 ? Params[1] : string.Empty, client.username).ToList();
                foreach (MessageArea area in list)
                {
                    Text.Add(TextHelper.Truncate(string.Format(fmt, new object[] {
                        area.Id, area.MessagesCount, area.NewMessagesCount(user.LastLoginDate),
                        area.UnreadMessagesCount(user.Userid), area.Description
                    }), client.screenWidth));
                    Data.Actions.Add(area.Id,
                                     new Parser.BBSCodeResult.Action()
                    {
                        module = "MessagesList",
                        data   = string.Format("@MessagesList;{0}", area.Id)
                    });
                }
            }
            KeyLength = 20;
        }
예제 #5
0
        /// <summary>
        /// Changes the local for the session and the user (if logged in)
        /// </summary>
        /// <param name="msg"></param>
        public override void HandleMessage(string msg)
        {
            if (string.IsNullOrWhiteSpace(msg) && KeyLength > 0)
            {
                msg = TextHelper.Truncate(Text[currentLine], KeyLength).Trim();
            }

            base.HandleMessage(msg);
            string l;

            if (codes.TryGetValue(msg.ToUpper(), out l))
            {
                client.locale = l;
                if (client.status == EClientStatus.LoggedIn)
                {
                    using (bbsContext bbs = new bbsContext())
                    {
                        User user = bbs.GetUserByUsername(client.username);
                        user.Locale = locale;
                        bbs.SaveChanges();
                    }
                }
                client.screen = ScreenFactory.Create(client, server, Previous.ModuleName(), Previous.ModuleParams());
                client.screen.Show();
            }
        }
예제 #6
0
        /// <summary>
        /// Dialog event loop
        /// </summary>
        /// <param name="msg"></param>
        public override void HandleMessage(string msg)
        {
            msg = msg.Trim();
            if (string.IsNullOrWhiteSpace(msg) && status != states.WaitForContinue)
            {
                return;
            }
            switch (status)
            {
            case states.WaitForUsername:
                msg = msg.ToUpper();
                if (msg == "EXIT")
                {
                    ShowNext();
                    return;
                }
                using (bbsContext bbs = new bbsContext())
                    user = bbs.GetUserByUsername(msg);
                if (user == null)
                {
                    LnWrite(catalog.GetString("User '{0}' is not found.", msg));
                    LnWrite(catalog.GetString("Username") + ": ");
                }
                else
                {
                    LnWrite(catalog.GetString("New password") + ": ");
                    client.inputMode = EInputMode.PasswordMode;
                    status           = states.WaitForNewPassword;
                }
                break;

            case states.WaitForNewPassword:
                handleWaitForNewPassword(msg);
                break;

            case states.WaitForConfirm:
                handleWaitForConfirm(msg);
                break;

            case states.WaitForContinue:
                ShowNext();
                break;

            default:
                break;
            }
        }
예제 #7
0
        /// <summary>
        /// Dialog events loop
        /// </summary>
        /// <param name="msg"></param>
        public override void HandleMessage(string msg)
        {
            switch (status)
            {
            case states.WaitForUsername:
                username = msg.Trim().ToUpper();
                if (username == string.Empty)
                {
                    break;
                }
                switch (username)
                {
                case "GUEST":
                    client.screen = ScreenFactory.Create(client, server, "TextScreen", "@GuestAccess");
                    client.screen.Show();
                    break;

                case "NEW":
                    client.screen = ScreenFactory.Create(client, server, "NewUser");
                    client.screen.Show();
                    break;

                case "LOGOUT":
                    client.screen = ScreenFactory.Create(client, server, "Logout");
                    client.screen.Show();
                    break;

                default:
                    LnWrite(catalog.GetString("Password") + ": ");
                    status           = states.WaitForPassword;
                    client.inputMode = EInputMode.PasswordMode;
                    break;
                }
                break;

            case states.WaitForPassword:
                string pwd = msg.Trim();
                client.status    = EClientStatus.Guest;
                client.inputMode = EInputMode.LineMode;
                bool success = false;

                using (bbsContext bbs = new bbsContext())
                {
                    User user = bbs.GetUserByUsername(username);
                    if (user != null)
                    {
                        Login login = new Login()
                        {
                            UserId = username, From = client.Remote
                        };
                        if (user.CheckPassword(pwd))
                        {
                            // successful login
                            success            = true;
                            user.LastLoginDate = DateTime.Now;
                            user.LastLoginFrom = client.Remote;
                            login.Success      = true;
                            bbs.Logins.Add(login);
                            try
                            {
                                bbs.SaveChanges();
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                                Console.WriteLine(e.InnerException.Message);
                            }

                            EventLogger.Write(string.Format("Successful login for user '{0}'", username),
                                              client.Remote);
                            client.status = EClientStatus.LoggedIn;
                            if (string.IsNullOrWhiteSpace(client.locale))
                            {
                                client.locale = user.Locale;
                            }
                        }
                        else
                        {
                            login.Success = false;
                            bbs.Logins.Add(login);
                            bbs.SaveChanges();
                            EventLogger.Write(string.Format("Password failed for user '{0}'", username),
                                              client.Remote);
                        }
                    }
                    else
                    {
                        EventLogger.Write(string.Format("Unknown user '{0}'", username),
                                          client.Remote);
                    }
                }

                if (success)
                {
                    client.username = username;
                    client.screen   = ScreenFactory.Create(client, server, "TextScreen", "@LoggedIn");
                    client.screen.Show();
                }
                else
                {
                    if (++tries >= maxtries)
                    {
                        client.screen = ScreenFactory.Create(client, server, "Logout");
                        client.screen.Show();
                    }
                    else
                    {
                        LnWrite(catalog.GetString("Username or password incorrect. Please try again."));
                        LnWrite(catalog.GetString("Username") + ": ");
                        status = states.WaitForUsername;
                    }
                }
                break;

            default:
                break;
            }
        }
예제 #8
0
        /// <summary>
        /// Exit a parse tree produced by <see cref="BBSCodeParser.bbsCodeElement"/>.
        /// </summary>
        /// <param name="context">The parse tree.</param>
        public override void ExitBbsCodeElement([NotNull] BBSCodeParser.BbsCodeElementContext context)
        {
            string tagName = context.children[1].GetText().Trim().ToUpper();
            Tags   tag;

            if (TagsTable.TryGetValue(tagName, out tag))
            {
                Attributes attr = AttributesTable.GetAttributes(tag);
                string     value;
                string     value1;
                switch (tag)
                {
                case Tags.CLS:
                    if (attr.TryGetValue("FORECOLOR", out value))
                    {
                        ANSI.pushForeColor(value);
                    }
                    if (attr.TryGetValue("BACKCOLOR", out value))
                    {
                        ANSI.pushBackColor(value);
                    }
                    Parsed.TextConcat(ANSI.ClearScreen());
                    Parsed.TextPop(true);
                    break;

                case Tags.BLINK:
                    ANSI.ResetMode(ANSICodes.Modes.Blink);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.REVERSE:
                    ANSI.ResetMode(ANSICodes.Modes.Reverse);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.BOLD:
                    ANSI.ResetMode(ANSICodes.Modes.Bold);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.UNDERLINE:
                    ANSI.ResetMode(ANSICodes.Modes.Underline);
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.COLOR:
                    ANSI.popForeColor();
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.BACKCOLOR:
                    ANSI.popBackColor();
                    Parsed.TextConcat(ANSI.WriteMode());
                    Parsed.TextPop(true);
                    break;

                case Tags.P:
                    Parsed.TextAssign(string.Join('\n',
                                                  TextHelper.WordWrap(Parsed.Parsed,
                                                                      Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.MOVE:
                    if (!attr.TryGetValue("ROW", out value))
                    {
                        value = "0";
                    }
                    if (!attr.TryGetValue("COL", out value1))
                    {
                        value1 = "0";
                    }
                    Parsed.TextConcat(ANSI.Move(value1, value));
                    Parsed.TextPop(true);
                    break;

                case Tags.FIGGLE:
                    if (!attr.TryGetValue("FONT", out value))
                    {
                        value = "standard";
                    }
                    try
                    {
                        Parsed.TextAssign(Figgle.FiggleFonts.Lookup(value.ToLower()).Render(Parsed.Parsed));
                    }
                    catch (Exception)
                    { }
                    Parsed.TextPop(true);
                    break;

                case Tags.ACTION:
                    action = new BBSCodeResult.Action(attr);
                    if (!string.IsNullOrWhiteSpace(action.requires))
                    {
                        if (string.IsNullOrWhiteSpace(Client.username))
                        {
                            Parsed.TextPop(true);
                            return;
                        }
                        using (bbsContext bbs = new bbsContext())
                        {
                            User user    = bbs.GetUserByUsername(Client.username);
                            bool allowed = user.HasRights(action.requires);
                            Parsed.TextPop(allowed);
                            if (!allowed)
                            {
                                return;
                            }
                        }
                    }
                    else
                    {
                        Parsed.TextPop(true);
                    }
                    if (!Parsed.Actions.TryAdd(action.key, action))
                    {
                        EventLogger.Write(string.Format("Error adding action '{0}' in '{1}'", action.key, FileName), 0);
                    }
                    break;

                case Tags.BEEP:
                    Parsed.TextConcat((char)7);
                    Parsed.TextPop(true);
                    break;

                case Tags.HR:
                    Parsed.TextConcat(TextHelper.HR('-', Client.screenWidth));
                    Parsed.TextPop(true);
                    break;

                case Tags.HEADER:
                    if (attr.TryGetValue("BACKCOLOR", out value))
                    {
                        Parsed.HeaderBackground = ANSI.GetColorByName(value, true);
                    }
                    Parsed.Header = Parsed.Parsed;
                    Parsed.TextClear();
                    break;

                case Tags.FOOTER:
                    if (attr.TryGetValue("BACKCOLOR", out value))
                    {
                        Parsed.FooterBackground = ANSI.GetColorByName(value, true);
                    }
                    Parsed.Footer = Parsed.Parsed;
                    Parsed.TextClear();
                    break;

                case Tags.BODY:
                    if (attr.TryGetValue("ALTERNATECOLOR", out value))
                    {
                        Parsed.BodyAlternateBackground = ANSI.GetColorByName(value, true);
                    }
                    if (attr.TryGetValue("FOCUSEDCOLOR", out value))
                    {
                        Parsed.BodyFocusedBackground = ANSI.GetColorByName(value, true);
                    }
                    Parsed.Body = Parsed.Parsed;
                    Parsed.TextClear();
                    break;

                case Tags.HIDDEN:
                    Parsed.TextClear();
                    break;

                case Tags.H1:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 1,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.H2:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 2,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.H3:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 3,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                case Tags.H4:
                    Parsed.TextAssign(string.Join('\n',
                                                  ANSI.Header(Parsed.Parsed, 1,
                                                              Client.screenWidth).ToArray()));
                    Parsed.TextPop(true);
                    break;

                default:
                    break;
                }
            }
        }
예제 #9
0
        /// <summary>
        /// Dialog events loop
        /// </summary>
        /// <param name="msg"></param>
        public override void HandleMessage(string msg)
        {
            msg = msg.Trim();
            if (string.IsNullOrWhiteSpace(msg))
            {
                if (status == states.WaitForConfirm)
                {
                    msg = catalog.GetString("Yes");
                }
                else if (status != states.WaitForUsername)
                {
                    return;
                }
            }
            switch (status)
            {
            case states.WaitForUsername:
                string username = msg.ToUpper();
                bool   success  = false;
                switch (username)
                {
                case "":
                    client.screen = ScreenFactory.Create(client, server, "LoginScreen");
                    client.screen.Show();
                    break;

                case "LOGOUT":
                    client.screen = ScreenFactory.Create(client, server, "Logout");
                    client.screen.Show();
                    return;

                case "GUEST":
                case "NEW":
                    break;

                default:
                    if (user.AcceptableUsername(username))
                    {
                        using (bbsContext bbs = new bbsContext())
                        {
                            User test = bbs.GetUserByUsername(username);
                            if (test == null)
                            {
                                success = true;
                            }
                        }
                    }
                    break;
                }
                if (success)
                {
                    user.Userid = username;
                    LnWrite(catalog.GetString("Password") + ": ");
                    status           = states.WaitForPassword;
                    client.inputMode = EInputMode.PasswordMode;
                }
                else
                {
                    LnWrite(catalog.GetString("This name is already in use. Try another."));
                    LnWrite(catalog.GetString("Username") + ": ");
                }
                break;

            case states.WaitForPassword:
                password = msg;
                if (user.AcceptablePassword(password))
                {
                    LnWrite(catalog.GetString("Confirm password") + ": ");
                    status = states.WaitForConfirmPassword;
                }
                else
                {
                    LnWrite(catalog.GetString("Password do not meet security criteria."));
                    LnWrite(catalog.GetString("Password") + ": ");
                    status = states.WaitForPassword;
                }
                break;

            case states.WaitForConfirmPassword:
                if (password == msg)
                {
                    user.SetPassword(password);
                    client.status    = EClientStatus.Guest;
                    client.inputMode = EInputMode.LineMode;
                    LnWrite(catalog.GetString("Your real name") + ": ");
                    status = states.WaitForRealName;
                }
                else
                {
                    LnWrite(catalog.GetString("The two passwords do not match. Try again."));
                    LnWrite(catalog.GetString("Password") + ": ");
                    status = states.WaitForPassword;
                }
                break;

            case states.WaitForRealName:
                user.Realname = msg;
                LnWrite(catalog.GetString("Your city") + ": ");
                status = states.WaitForCity;
                break;

            case states.WaitForCity:
                user.City = msg;
                LnWrite(catalog.GetString("Your country") + ": ");
                status = states.WaitForNation;
                break;

            case states.WaitForNation:
                user.Nation = msg;
                LnWrite(catalog.GetString("Confirm new user creation? [{0}]/{1}",
                                          new object[] {
                    catalog.GetString("Yes"), catalog.GetString("No")
                }) + ": ");
                status = states.WaitForConfirm;
                break;

            case states.WaitForConfirm:
                msg = msg.ToUpper();
                if (msg == catalog.GetString("Yes").ToUpper())
                {
                    using (bbsContext bbs = new bbsContext())
                    {
                        bbs.Users.Add(user);
                        bbs.SaveChanges();
                    }
                    string m = catalog.GetString("Created new user '{0}'", user.Userid);
                    EventLogger.Write(m, client.Remote);
                }
                client.screen = ScreenFactory.Create(client, server, "LoginScreen");
                client.screen.Show();
                break;

            default:
                break;
            }
        }