Beispiel #1
0
        public void login(SubscribedUser user)
        {
            loggedInUser[user.getUsername()] = user;
            string username = user.getUsername();
            string password = user.getPassword();

            try
            {
                lock (connection)
                {
                    connection.Open();
                    //SqlConnection connection = Connector.getInstance().getSQLConnection();
                    var c = connection.Query("SELECT username, password FROM [dbo].[Register] WHERE username=@username ", new { username = username });
                    //connection.Close();
                    if (Enumerable.Count(c) == 0)
                    {
                        throw new LoginException("Username " + user.getUsername() + "does not exist");
                    }
                    connection.Close();
                }
            }
            catch (Exception e)
            {
                if (e is ClientException)
                {
                    throw e;
                }
                else
                {
                    connection.Close();
                    SystemLogger.getErrorLog().Error("Connection error in function login in db subscribed user, user name: " + user.getUsername());
                    throw new ConnectionException();
                }
            }
        }
Beispiel #2
0
        public void login(String username, String password, Session session)
        {
            String         encrypted = DBSubscribedUser.getInstance().encryptPassword(password);
            SubscribedUser sub       = DBSubscribedUser.getInstance().getSubscribedUser(username);

            if (sub == null)
            {
                throw new LoginException("Username does not exist");
            }
            SubscribedUser loggedIn = DBSubscribedUser.getInstance().getloggedInUser(username);

            if (loggedIn != null)
            {
                throw new LoginException("Username already logged in");
            }
            if (!Equals(sub.getPassword(), encrypted))
            {
                throw new LoginException("Incorrect password");
            }
            session.setSubscribedUser(sub);
            if (Equals(username, "admin"))
            {
                session.setState(new Admin());
            }
            else
            {
                session.setState(new LoggedIn());
            }
            session.setShoppingBasket(sub.getShoppingBasket());
            DBSubscribedUser.getInstance().login(sub);
        }
Beispiel #3
0
        public void register(SubscribedUser user)
        {
            users.Add(user.getUsername(), user);
            string username = user.getUsername();
            string password = user.getPassword();

            try
            {
                lock (connection)
                {
                    connection.Open();
                    //SqlConnection connection = Connector.getInstance().getSQLConnection();
                    var c = connection.Query("SELECT username, password FROM [dbo].[Register] WHERE username=@username ", new { username = username });
                    //connection.Close();
                    if (Enumerable.Count(c) == 0)
                    {
                        string sql = "INSERT INTO [dbo].[Register] (username, password)" +
                                     " VALUES (@username, @password)";
                        connection.Execute(sql, new { username, password });
                    }
                    connection.Close();
                }
            }
            catch (Exception e)
            {
                connection.Close();
                SystemLogger.getErrorLog().Error("Connection error in function register in db subscribed user, user name: " + user.getUsername());
                throw new ConnectionException();
            }
        }
Beispiel #4
0
        public void loginAfterRegister(String username, String password, Session session)
        {
            String         encrypted = password;
            SubscribedUser sub       = DBSubscribedUser.getInstance().getSubscribedUser(username);

            if (sub == null)
            {
                throw new LoginException("Error: Username does not exist");
            }
            DBSubscribedUser.getInstance().updateStoreRole(sub);
            //SubscribedUser loggedIn = DBSubscribedUser.getInstance().getloggedInUser(username);
            //if( loggedIn != null)
            //    throw new LoginException("Error: Username already logged in");
            if (!Equals(sub.getPassword(), encrypted))
            {
                throw new LoginException("Error: Incorrect password");
            }
            ////////////erase

            // Store st = new Store("bb", "cc");
            //DBStore.getInstance().addStore(st);



            ////////erase
            session.setSubscribedUser(sub);

            if (Equals(username, "u1"))
            {
                session.setState(new Admin());
            }
            else
            {
                session.setState(new LoggedIn());
            }
            session.setShoppingBasket(new ShoppingBasket(sub.getUsername()));
            session.setShoppingBasket(sub.getShoppingBasket());
            DBSubscribedUser.getInstance().login(sub);
        }