Ejemplo n.º 1
0
        public RegisterResult InsertUser(User user)
        {
            ParagonDataContext ctx = new ParagonDataContext();


            if (UsernameExists(user.Username))
            {
                return(RegisterResult.UsernameExists);
            }
            if (EmailExists(user.Email))
            {
                return(RegisterResult.EmailExists);
            }
            if (UsernameTooLong(user.Username))
            {
                return(RegisterResult.UsernameTooLong);
            }
            if (!IsInvalidEmail(user.Email))
            {
                return(RegisterResult.InvalidEmail);
            }

            ctx.Users.InsertOnSubmit(user);
            ctx.SubmitChanges();

            return(ctx.Users.Contains(user) ? RegisterResult.Success : RegisterResult.UnknownFailure);
        }
Ejemplo n.º 2
0
        public LoginResult UserExists(string username, string password)
        {
            ParagonDataContext ctx = new ParagonDataContext();

            username = username.ToLower();

            User user = ctx.Users.FirstOrDefault(x =>
                                                 UsernameExists(username) ||
                                                 EmailExists(username));

            if (user == null)
            {
                return(LoginResult.WrongUsername); //User doesn't exist, user must have entered wrong username/email.
            }
            if (user.Password == password.Hash <SHA256Managed>(user.Hash))
            {
                return(LoginResult.Success); //User password == given password :D
            }
            //User password is not == to given password, return WrongPassword.
            return(LoginResult.WrongPassword);
        }
Ejemplo n.º 3
0
        public static bool Initialize()
        {
            ApplicationSettings.Initialize();
            while (true)
            {
                //TODO: Get rid of this try. Not sure what I was doing originally.
                //This is completely broken and just (predictably) fails if it can't connect to the database or what have you.
                //Kinda makes it hard for someone to set this up if they don't know what I was doing, which if I'm being honest, I didn't.
                try
                {
                    ParagonDataContext ctx = new ParagonDataContext();
                    //TODO: Pretty sure this fails everytime if the database doesn't exist so go me, this is very helpful. Idiot.
                    if (!ctx.DatabaseExists())
                    {
                        ctx.CreateDatabase();
                    }

                    _userAccessor = new UserAccessor();


                    return(true);
                }
                catch (Exception)
                {
                    //So I just spent like 3 hours trying to get a SQL Server running and this never popped up once. I have no idea what I was doing.
                    using (DataConnectionDialog dialog = new DataConnectionDialog())
                    {
                        DataConnectionConfiguration dcs = new DataConnectionConfiguration(null);
                        dcs.LoadConfiguration(dialog);
                        if (DataConnectionDialog.Show(dialog) != DialogResult.OK)
                        {
                            return(false);
                        }
                        string connectionString = dialog.ConnectionString;

                        ApplicationSettings.ConnectionString = connectionString;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public User FindUserFromUsername(string username)
        {
            ParagonDataContext ctx = new ParagonDataContext();

            return(ctx.Users.FirstOrDefault(x => x.Username == username.ToLower()));
        }
Ejemplo n.º 5
0
 public UserAccessor()
 {
     _context = new ParagonDataContext();
 }