Esempio n. 1
0
        void btnLogin_ServerClick(object sender, EventArgs e)
        {
            var userName = this.user.Value;
            var pwd      = this.password.Value;

            // 先检查用户名在本系统里面有没有
            var user = UserLoader.GetUserByName(userName);

            if (user == null)
            {
                ClientMessageHelper.Alert(Page, "用户名不存在".GetRes());
                WFLog.WriteLog("系统登录".GetRes(), userName, string.Format("用户名不存在,客户端IP地址 {0}".GetRes(), IPHelper.GetClientIPAddress()), WFLog.LOGLEVEL_ERROR, userName);
                return;
            }
            if (user.Status != 1)
            {
                ClientMessageHelper.Alert(Page, "用户已经被禁用".GetRes());
                WFLog.WriteLog("系统登录".GetRes(), userName, string.Format("用户已经被禁用,客户端IP地址 {0}".GetRes(), IPHelper.GetClientIPAddress()), WFLog.LOGLEVEL_WARN, userName);
                return;
            }

            // 先本机验证,如果本机验证不通过,进行域验证
            //
            // 发布的时候需要设置成 Release 模式进行发布
            //
            if (!Verify(userName, pwd))
            {
                ClientMessageHelper.Alert(Page, "用户名密码错误".GetRes());
                WFLog.WriteLog("系统登录".GetRes(), userName, string.Format("用户名密码错误,客户端IP地址 {0}".GetRes(), IPHelper.GetClientIPAddress()), WFLog.LOGLEVEL_ERROR, userName);
                return;
            }
            WFLog.WriteLog("系统登录".GetRes(), userName, string.Format("用户成功登录,客户端IP地址 {0}".GetRes(), IPHelper.GetClientIPAddress()), WFLog.LOGLEVEL_INFO, userName);
            InitUserSession(user.UserId, dpLanguage.SelectedValue.ToString());
            Response.Redirect(GetReturnUrl());
        }
Esempio n. 2
0
    public void LoadUsers()
    {
        UserLoader ul = new UserLoader();

        ul    = Serializacion.LoadDataFromDisk <UserLoader>(path, false);
        users = ul.list;
    }
Esempio n. 3
0
        public static bool Verify(string userName, string password)
        {
            // 默认两种验证方式
            var domain = string.Format("{0}", WFCorePublicCodeHelper.GetPublicCode("Domain", "Authentication Method", "Domain,Password")).ToLower();

            if (domain.Contains("password"))
            {
                var user = UserLoader.GetUserByName(userName);
                if (user != null)
                {
                    var uesrHash = HashHelper.GenerateUserHash(userName, password);
                    if (uesrHash == user.Password)
                    {
                        return(true);
                    }
                }
            }
            if (domain.Contains("domain"))
            {
                if (IsValidDomainUser(userName, password))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 4
0
 /// <summary>
 /// Method for initializing user object
 /// </summary>
 /// <param name="id">
 /// id of user
 /// </param>
 /// <param name="name">
 /// name of user
 /// </param>
 /// <param name="jwt">
 /// jwt object used to authorize user on backend
 /// </param>
 /// <param name="models">
 /// All models owned by user
 /// </param>
 /// <param name="loader">
 /// User loader used to create this user
 /// </param>
 private void Init(UserJSONData jsonData, UserLoader loader)
 {
     this._userLoader = loader;
     SetData(jsonData);
     //Has to be invoked after set data - require setting of id!
     CreateUserDirIfNotExists();
 }
Esempio n. 5
0
    public void SaveUsers()
    {
        UserLoader ul = new UserLoader();

        ul.list = users;
        ul.SaveDataToDisk(path, false);
    }
        public User Authenticate(string username, string password)
        {
            var userLoader = new UserLoader();
            var users      = userLoader.LoadUsers();

            return(users.FirstOrDefault(x => x.Username == username && x.Password == password));
        }
Esempio n. 7
0
        private void ContinueButton_Click(object sender, EventArgs e)
        {
            if (loginValidator.IsCorrect(ChatServer.Encryptor.Encrypt(nicknameText.Text), ChatServer.Encryptor.Encrypt(passwordText.Text), (string)userTypeBox.SelectedItem))
            {
                UserLoader userLoader = new UserLoader();
                userLoader.LoadUser(ChatServer.Encryptor.Encrypt(nicknameText.Text), ChatServer.Encryptor.Encrypt(passwordText.Text), (string)userTypeBox.SelectedItem);
                Dispose();
            }
            else
            {
                nicknameText.Text = "";
                passwordText.Text = "";
                versionLabel.Text = "BAD DATA ENTERED";
                Timer timer = new Timer()
                {
                    Interval = 2000,
                    Enabled  = true
                };

                timer.Tick += (tsender, ev) => {
                    versionLabel.Text = "Version v1.1";

                    timer.Dispose();
                };
            }
        }
Esempio n. 8
0
    /// <summary>
    /// Method for loading loggedUser based on player prefs content
    /// </summary>
    /// <returns>
    /// Was user succesfully logged from prefabs
    /// </returns>
    public bool LoginUserFromPlayerPrefs()
    {
        //Generating string from player prefs
        var jsonString = PlayerPrefs.GetString(loggedUserLabel, null);

        //if json is not null - user exists in player prefs
        if (!String.IsNullOrEmpty(jsonString))
        {
            //Generating json data from string
            var jsonData = UserLoader.GetUserJSONDataFromString(jsonString);

            //Generating user from json data
            var user = UserLoader.GenerateUserFromJSONData(jsonData, this);

            UserLoader._loggedUser = user;

            Translator.SetLanguageFromLoggedUser();

            return(true);
        }
        else
        {
            //if json is null - there is no user in player prefs - set currently logged user as null
            UserLoader._loggedUser = null;

            return(false);
        }
    }
Esempio n. 9
0
        protected override void Seed(DataContext context)
        {
            // application values
            var applicationValues = new ApplicationValueLoader().LoadApplicationValues();

            applicationValues.ForEach(s => context.ApplicationValues.Add(s));
            context.SaveChanges();

            // users
            var users = new UserLoader().LoadUsers();

            users.ForEach(s => context.Users.Add(s));
            context.SaveChanges();

            // captions
            var captions = new CaptionLoader().LoadCaptions();

            captions.ForEach(s => context.Captions.Add(s));
            context.SaveChanges();

            // posts
            var posts = new PostLoader().LoadPosts();

            // assign captions to each post
            foreach (var post in posts)
            {
                var postCaptions = context.Captions.Take(new Random().Next(0, 10)).ToList();
                post.Captions = postCaptions;
            }
            posts.ForEach(s => context.Posts.Add(s));
            context.SaveChanges();
        }
Esempio n. 10
0
        public static void Main(string[] args)
        {
            var conn = new MySqlConnection("server=localhost;user=yelp_etl;password=P@ssword!;port=3306;");

            Console.WriteLine("Creating database: yelp...");

            try
            {
                DropDatabaseIfExist(conn);
                conn.Open();
                conn.Execute(File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "data", "yelp_db.sql")));
            }
            finally
            {
                conn.Close();
            }

            Console.WriteLine("Database created.");

            try
            {
                Console.WriteLine("Starting load...");

                //Long running task should start first
                var t1 = Task.Run(() => BusinessLoader.Load(Helpers.CreateConnectionToYelpDb()));
                var t2 = Task.Run(() => ReviewLoader.Load(Helpers.CreateConnectionToYelpDb()));

                //Faster loaders can run sequencially
                CheckinLoader.Load(Helpers.CreateConnectionToYelpDb());
                TipLoader.Load(Helpers.CreateConnectionToYelpDb());
                UserLoader.Load(Helpers.CreateConnectionToYelpDb());

                Task.WaitAll(t1, t2);
                Console.WriteLine("Load complete.");
            }
            catch (AggregateException aEx)
            {
                Console.WriteLine("Load Failure.");

                foreach (var ex in aEx.Flatten().InnerExceptions)
                {
                    Console.WriteLine(ex.Message);
                }

                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Load Failure: {ex.Message}.");
                DropDatabaseIfExist(conn);
            }

            conn.Dispose();

            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();
        }
Esempio n. 11
0
    /// <summary>
    /// Method for getting user data from server
    /// </summary>
    /// <param name="jwt">
    /// JWT of currently logged user
    /// </param>
    /// <returns>
    /// user data as JSON (string)
    /// </returns>
    public static async Task <UserJSONData> GetUserDataFromServer(string jwt)
    {
        //timeout = 10 sec
        using (var webClient = new WebclientWithTimeout(10 * 1000))
        {
            webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
            webClient.Headers["x-auth-token"] = jwt;

            var testJSONUserData = await webClient.DownloadStringTaskWithTimeoutAsync(UserService.userApiURL);

            var userJsonObject = UserLoader.GetUserJSONDataFromString(testJSONUserData);
            return(userJsonObject);
        }
    }
Esempio n. 12
0
    /// <summary>
    /// Method for saving logged user data into player prefs
    /// </summary>
    public void SaveLoggedUserToPlayerPrefs()
    {
        if (UserLoader.LoggedUser != null)
        {
            var jsonData   = UserLoader.GenerateJSONDataFromUser(UserLoader.LoggedUser);
            var jsonString = UserLoader.GetStringFromUserJSONData(jsonData);

            //Setting json string to player prefs
            PlayerPrefs.SetString(loggedUserLabel, jsonString);
        }
        else
        {
            //Removing data from player prefs if there is no logged user
            PlayerPrefs.SetString(loggedUserLabel, null);
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Method for generating json user data based on given user object
    /// </summary>
    /// <param name="user">
    /// user Object
    /// </param>
    /// <returns>
    /// User data in the form of JSON
    /// </returns>
    public static UserJSONData GenerateJSONDataFromUser(User user)
    {
        var jsonToReturn = new UserJSONData();

        jsonToReturn._id           = user.ID;
        jsonToReturn.name          = user.Name;
        jsonToReturn.email         = user.Email;
        jsonToReturn.jwt           = user.JWT;
        jsonToReturn.permissions   = user.Permissions;
        jsonToReturn.defaultLang   = user.DefaultLang;
        jsonToReturn.modelIds      = UserLoader.GenerateAssetModelIds(user.ModelList);
        jsonToReturn.modelNames    = UserLoader.GenerateAssetModelNames(user.ModelList);
        jsonToReturn.filesExist    = UserLoader.GenerateAssetModelFileExists(user.ModelList);
        jsonToReturn.iosFilesExist = UserLoader.GenerateAssetModelIOSFileExists(user.ModelList);

        return(jsonToReturn);
    }
Esempio n. 14
0
        private void InitUserSession(string userId, string language)
        {
            var session = SessionHelper.RefreshUserToken(userId, "PCClient");
            // 更新用户登录最后时间

            /// <summary>
            /// 设置 Cookie
            /// </summary>
            /// <param name="session"></param>
            /// <param name="language"></param>

            var expiredTime = session.Expire ?? DateTime.Now.AddHours(4);

            SetLanguageCookie(language, expiredTime);

            // 更新用户登录最后时间
            UserLoader.Update(userId, DateTime.Now);
        }
Esempio n. 15
0
    /// <summary>
    /// Method for getting user data from server
    /// </summary>
    /// <param name="email">
    /// Email of user
    /// </param>
    /// <param name="password">
    /// User's password
    /// </param>
    /// <returns>
    /// user data as JSON (string)
    /// return null in case id or password is invalid
    /// </returns>
    public static async Task <UserJSONData> GetUserDataFromServer(string email, string password)
    {
        //timeout = 10 sec
        using (var webClient = new WebclientWithTimeout(10 * 1000))
        {
            //Creating Object to parse to JSON content based on given credentials
            var newAuthObject = new AuthJSONData();
            newAuthObject.email    = email;
            newAuthObject.password = password;

            //Generating JSON content
            var jsonAuthObject = JsonUtility.ToJson(newAuthObject);

            webClient.Headers[HttpRequestHeader.ContentType] = "application/json";

            var testJSONUserData = await webClient.UploadStringTaskWithTimeoutAsync(UserService.authApiURL, jsonAuthObject);

            var userJsonObject = UserLoader.GetUserJSONDataFromString(testJSONUserData);
            return(userJsonObject);
        }
    }
Esempio n. 16
0
        public override string Display()
        {
            bool notSufficentInformation = true;

            do
            {
                base.Display();
                var adminMainView = new AdminMainView();
                var userLoader    = new UserLoader();

                Console.WriteLine("Register user\n");
                Console.Write("Select username: "******"Select password: "******"Select role: ");
                string role = Console.ReadLine();

                Console.WriteLine("\nIs this correct? [Y]es [N]o");
                var consolekeyInfo = Console.ReadKey();

                if (consolekeyInfo.Key == ConsoleKey.Y)
                {
                    var user  = new User(username, password, role);
                    var users = new List <User>();
                    users.Add(user);

                    adminMainView.Display();
                }
                else
                {
                    adminMainView.Display();
                }
            } while (notSufficentInformation);

            return("");
        }
Esempio n. 17
0
 public void Setup()
 {
     _userRepositoryMock = new Mock <IUserRepository>();
     _userManager        = new UserLoader(_userRepositoryMock.Object);
 }
Esempio n. 18
0
 /// <summary>
 /// Class representing user
 /// </summary>
 /// <param name="jsonData">
 /// json data of user
 /// </param>
 /// <param name="loader">
 /// User loader used to create this user
 /// </param>
 public User(UserJSONData jsonData, UserLoader loader)
 {
     Init(jsonData, loader);
 }
Esempio n. 19
0
 /// <summary>
 /// Method for generating user based on json data
 /// </summary>
 /// <param name="jsonData">
 /// Json data of user
 /// </param>
 /// <param name="loader">
 /// User loader used to generate user object
 /// </param>
 /// <returns>
 /// User object
 /// </returns>
 public static User GenerateUserFromJSONData(UserJSONData jsonData, UserLoader loader)
 {
     return(new User(jsonData, loader));
 }
Esempio n. 20
0
 public LoginController()
 {
     IoC.AddModule <WebAppExampleDataDependencyModule>();
     _userLoader = IoC.Get <UserLoader>();
 }
Esempio n. 21
0
        public void Display()
        {
            var searchUser = new SearchUser();
            var userLoader = new UserLoader();
            var done       = false;

            do
            {
                Console.Clear();
                Console.WriteLine(" # Search User");
                Console.WriteLine("\n Search by username:"******"\n > ");

                var searchName = Console.ReadLine();
                var searchHits = searchUser.UserSearch(searchName);
                var deleteUser = new DeleteUser();

                if (searchHits.Any())
                {
                    Console.Clear();
                    Console.WriteLine($" # Users matching your search: {searchName}\n");
                    foreach (var searchHit in searchHits)
                    {
                        Console.WriteLine($" Username: {searchHit.Username}");
                    }

                    Console.Write($"\n (D)elete (V)iew (E)xit");

                    var choice = Console.ReadKey(true);

                    if (choice.Key == ConsoleKey.D)
                    {
                        Console.Clear();
                        foreach (var searchHit in searchHits)
                        {
                            Console.WriteLine($" Username: {searchHit.Username}");
                        }

                        Console.Write($"\n Delete> ");

                        string userForDeletion = Console.ReadLine();
                        deleteUser.UserDelete(userForDeletion);

                        Console.WriteLine($" User with username: {userForDeletion}  deleted successfully.");
                        Thread.Sleep(2000);
                        done = true;
                    }
                    else if (choice.Key == ConsoleKey.V)
                    {
                        Console.Clear();
                        foreach (var searchHit in searchHits)
                        {
                            Console.WriteLine($" Username: {searchHit.Username}");
                        }

                        Console.Write($"\n View details for user> ");

                        var userForViewing = Console.ReadLine();
                        if (userLoader.LoadUsers(userForViewing) != null)
                        {
                            Console.WriteLine($" User name:     {userLoader.LoadUsers(userForViewing).Username}.");
                            Console.WriteLine($" User password: {userLoader.LoadUsers(userForViewing).Password}");
                            Console.WriteLine($" User role:     {userLoader.LoadUsers(userForViewing).Role}");
                            Console.Write("\n Delete user (Y)es (N)o");

                            if (Console.ReadKey().Key == ConsoleKey.Y)
                            {
                                Console.Write($"\n Are you certain?  (Y)es (N)o");
                                var confirm = Console.ReadKey(true);
                                if (confirm.Key == ConsoleKey.Y)
                                {
                                    deleteUser.UserDelete(userForViewing);
                                    Console.Write($"User deleted successfully.");
                                    Thread.Sleep(2000);
                                    done = true;
                                }
                            }
                            else
                            {
                                done = true;
                            }
                        }
                        else
                        {
                            Console.Write("Invalid input, press any key");
                            Console.ReadKey();
                            done = true;
                        }
                    }
                    else
                    {
                        done = true;
                    }
                }
                else
                {
                    Console.WriteLine($" No users found matching the search term {searchName}.");
                    Thread.Sleep(2000);
                }
            } while (!done);
        }