Exemple #1
0
        // !!! revoir cette méthode pour la rendre standard et implémenter les méthode officiel de login
        public LocalUser AuthLogin(string UserName, string Password)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(UserName) || string.IsNullOrWhiteSpace(Password))
                {
                    throw new Exception("Credentials Invalids");
                }
                Dictionary <string, object> ins = new Dictionary <string, object>();
                ins.Add("UserName", UserName);
                ins.Add("PasswordHash", UserTools.PasswordHash(Password));

                string sql = "SELECT * FROM identity_users WHERE UserName=@UserName AND PasswordHash=@PasswordHash";
                System.Data.DataTable ret = this.userProvider.Connector.Query(sql, ins);
                if (ret.Rows.Count == 0)
                {
                    return(null);
                }

                LocalUser user = new LocalUser(ret.Rows[0]);
                user._IsAuthenticated = true; // Warning
                return(user);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public LocalUser CreateUser(FORM.CreateUserForm form, ACCOUNT.Account account)
        {
            try
            {
                form.Validate();
                if (GetUser(form.Mail, 0, false) != null)
                {
                    throw new Exception("User Already Found");
                }
                LocalUser retour = new LocalUser();
                retour.IDAccount = account.IDAccount;
                retour["iduser"] = DBNull.Value;

                if (string.IsNullOrWhiteSpace(form.Pseudo))
                {
                    retour.Pseudo = form.Mail;
                }
                else
                {
                    retour.Pseudo = form.Pseudo;
                }
                retour.UserName      = form.Mail;
                retour.SecurityMail  = form.Mail;
                retour.SecurityPhone = form.Phone;
                if (!string.IsNullOrWhiteSpace(form.Password))
                {
                    retour.Password = UserTools.PasswordHash(form.Password);
                }
                retour["DateCreate"] = DateTime.Now;
                retour["DateUpdate"] = DateTime.Now;
                retour.UserLevel     = string.IsNullOrWhiteSpace(form.Password) ? ENUMS.UserLevelEnum.DISABLED : ENUMS.UserLevelEnum.STANDARD;

                this.InsertBubble(retour, false, true);

                return(retour);
            }
            catch (Exception ex)
            {
                throw new Exception("CreateUser " + ex.Message);
            }
        }
        public LocalUser UpdatePasswordToken(string UserName, string password)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(UserName) || string.IsNullOrWhiteSpace(password))
                {
                    throw new Exception("Credentials Invalids");
                }
                Dictionary <string, object> ins = new Dictionary <string, object>();
                ins.Add("userName", UserName);
                ins.Add("PasswordHash", UserTools.PasswordHash(password));

                string sql = "UPDATE identity_users SET passwordHash=@PasswordHash WHERE username=@username";
                System.Data.DataTable ret = this.Connector.Query(sql, ins);

                return(null);
            }
            catch (Exception)
            {
                throw;
            }
        }