public string ResetPassword(IUserContext userContext, string email, string passwordResponse)
        {
            string newPassword = null;

            using (var et = new ExecutionTracerService())
                using (var db = new UserCrud(userContext))
                {
                    var options = new SearchOptions();

                    options.Filters.Add(User.ColumnNames.Email, FilterOperator.Equals, email);
                    options.Filters.Add(User.ColumnNames.PasswordResponse, FilterOperator.Equals, passwordResponse);

                    var users = db.Search(ref options);
                    if (users.Count == 1)
                    {
                        var user = users.First();

                        newPassword   = RandomHelper.GetRandomString(8);
                        user.Password = HashHelper.EncodeWithSha1(newPassword);

                        db.Save(ref user);

                        Task.Run(() => SendMailOnPasswordResetAsync(user, newPassword));                 // background
                    }
                }

            return(newPassword);
        }
Example #2
0
        public void GetUsersThroughput_ThroughputMode(BenchmarkContext context)
        {
            UserCrud    usercrud = new UserCrud();
            List <User> user     = usercrud.GetAllUser().ToList();

            addCounter.Increment();
        }
 /// <summary>
 /// Indicates whether the search returns at least 1 entity.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="options">
 /// Optional search options. If not defined, all records are returned.
 /// </param>
 ///
 /// <returns>
 /// True if the search returns at least 1 entity; otherwise, false.
 /// </returns>
 public bool HasResult(IUserContext userContext, SearchOptions options = null)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             return(db.HasResult(options));
         }
 }
 /// <summary>
 /// Gets entities with search options.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="options">
 /// Optional options, filters, orderby, paging, etc.
 /// </param>
 ///
 /// <returns>
 /// A collection of entities.
 /// </returns>
 public TCollection <VahapYigit.Test.Models.User> Search(IUserContext userContext, ref SearchOptions options)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             return(db.Search(ref options));
         }
 }
 /// <summary>
 /// Gets an entity given its email value.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="email">
 /// Unique email value.
 /// </param>
 ///
 /// <returns>
 /// The entity.
 /// </returns>
 public VahapYigit.Test.Models.User GetByIdentifier(IUserContext userContext, string email)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             return(db.GetByIdentifier(email));
         }
 }
 /// <summary>
 /// Deletes the entity given its unique ID.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="id">
 /// Unique ID.
 /// </param>
 ///
 /// <returns>
 /// The number of affected rows.
 /// </returns>
 public int Delete(IUserContext userContext, long id)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             return(db.Delete(id));
         }
 }
 public UserManager()
 {
     UCrud        = new UserCrud();
     RCrud        = new RoleCrud();
     PasswordCrud = new UserPasswordCrud();
     VCrud        = new ViewCrud();
     TCrud        = new TerminalCrud();
 }
 /// <summary>
 /// Loads the UserRole entities associated to the instances (entity.UserRole collection property).
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="entities">
 /// The target entity collection.
 /// </param>
 public void LoadUserRoleCollection(IUserContext userContext, TCollection <VahapYigit.Test.Models.User> entities)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             db.LoadUserRoleCollection(entities);
         }
 }
 /// <summary>
 /// Refreshs the entity instance from the database.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="appSettings">
 /// Entity to refresh (must be in database).
 /// </param>
 public void Refresh(IUserContext userContext, ref VahapYigit.Test.Models.User entity)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             db.Refresh(ref entity);
         }
 }
Example #10
0
 /// <summary>
 /// Gets an entity given its unique ID.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="id">
 /// Unique ID.
 /// </param>
 ///
 /// <returns>
 /// The entity.
 /// </returns>
 public VahapYigit.Test.Models.User GetById(IUserContext userContext, long id)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             return(db.GetById(id));
         }
 }
Example #11
0
 /// <summary>
 /// Deletes the entity from the database.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="entity">
 /// Entity to delete.
 /// </param>
 ///
 /// <returns>
 /// The number of affected rows.
 /// </returns>
 public int Delete(IUserContext userContext, VahapYigit.Test.Models.User entity)
 {
     using (var et = new ExecutionTracerService())
         using (var db = new UserCrud(userContext))
         {
             return(db.Delete(entity));
         }
 }
Example #12
0
 /// <summary>
 /// Saves (or updates) the entity in the database.
 /// </summary>
 ///
 /// <param name="userContext">
 /// User context.
 /// </param>
 ///
 /// <param name="entity">
 /// Entity to save or update.
 /// </param>
 ///
 /// <param name="options">
 /// Optional options.
 /// </param>
 ///
 /// <returns>
 /// The number of affected rows.
 /// </returns>
 public int Save(IUserContext userContext, ref VahapYigit.Test.Models.User entity, SaveOptions options = null)
 {
     using (var et = new ExecutionTracerService(tag: entity.State.ToString()))
         using (var db = new UserCrud(userContext))
         {
             return(db.Save(ref entity, options));
         }
 }
Example #13
0
 public CardManager()
 {
     CrudFactory  = new CardCrud();
     UCrud        = new UserCrud();
     TerminalCrud = new TerminalCrud();
     CtCrud       = new CardTypeCrud();
     SyParam      = new SystemParamCrud();
     PayCrud      = new PaymentCrud();
     PTCrud       = new PaymentTerminalCrud();
 }
        public bool IsEmailUsed(IUserContext userContext, string email)
        {
            using (var et = new ExecutionTracerService())
                using (var db = new UserCrud(userContext))
                {
                    var options = new SearchOptions();
                    options.Filters.Add(User.ColumnNames.Email, FilterOperator.Equals, email);

                    return(db.HasResult(options));
                }
        }
Example #15
0
        public static void Initialize(IDatabaseConnectionDescriptor descriptor)
        {
            System.Diagnostics.Debug.WriteLine("Krile DB Initializing...");
            if (_isInitialized)
            {
                throw new InvalidOperationException("Database core is already initialized.");
            }
            _isInitialized = true;
            _descriptor    = descriptor;

            // register sqlite functions
            var asm = Assembly.GetExecutingAssembly();

            asm.DefinedTypes.Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(SQLiteFunction)))
            .Where(t => t.GetCustomAttribute <SQLiteFunctionAttribute>() != null)
            .ForEach(t =>
            {
                try
                {
                    SQLiteFunction.RegisterFunction(t);
                }
                catch
                {
                }
            });

            // initialize tables
            var tasks = new Task[] { };

            Task.WaitAll(Task.Factory.StartNew(() =>
            {
                tasks = new[]
                {
                    AccountInfoCrud.InitializeAsync(descriptor),
                    StatusCrud.InitializeAsync(descriptor),
                    StatusEntityCrud.InitializeAsync(descriptor),
                    UserCrud.InitializeAsync(descriptor),
                    UserDescriptionEntityCrud.InitializeAsync(descriptor),
                    UserUrlEntityCrud.InitializeAsync(descriptor),
                    ListCrud.InitializeAsync(descriptor),
                    ListUserCrud.InitializeAsync(descriptor),
                    FavoritesCrud.InitializeAsync(descriptor),
                    RetweetsCrud.InitializeAsync(descriptor),
                    RelationCrud.InitializeAsync(descriptor),
                    ManagementCrud.InitializeAsync(descriptor)
                };
            }));
            Task.WaitAll(tasks);
        }
Example #16
0
        public void GetUserList()
        {    //Arrange
            UserCrud userBusiness = new UserCrud();
            //Act
            User user = userBusiness.GetUser(1);

            //Assert
            if (user != null)
            {
                Assert.AreEqual(1, user.UserId);
            }
            else
            {
                Assert.IsNotNull(user);
            }
        }
Example #17
0
        public void PostUserTest()
        {    //Arrange
            UserCrud user  = new UserCrud();
            User     usObj = new User();

            usObj.UserId     = 0;
            usObj.FirstName  = "FirstName";
            usObj.LastName   = "LastName";
            usObj.EmployeeId = 1234;

            //Act
            usObj = user.AddUser(usObj);

            //Assert
            Assert.AreNotEqual(0, usObj.UserId);
        }
        public bool IsRegistered(IUserContext userContext, out User user)
        {
            bool bIsRegistered = false;

            user = null;

            using (var et = new ExecutionTracerService())
                using (var userCrud = new UserCrud(userContext))
                    using (var userRoleCrud = new UserRoleCrud(userContext))
                        using (var roleCrud = new RoleCrud(userContext))
                        {
                            var options = new SearchOptions {
                                MaxRecords = 1
                            };

                            // Note about the the first parameter (orGroup) -> different values -> OR operator
                            // Thus userContext.Identifier can contain either the Username or the email address (Unique constraint on these values)

                            options.Filters.Add(0, User.ColumnNames.Username, FilterOperator.Equals, userContext.Identifier);
                            options.Filters.Add(1, User.ColumnNames.Email, FilterOperator.Equals, userContext.Identifier);

                            var users = userCrud.Search(ref options);
                            if (users.Count == 1)
                            {
                                user = users.First();
                                if (user.Password == userContext.Password)         // because of French_CI_AI collation at SQL Server side (Case Insensitive, Accent Insensitive)
                                {
                                    bIsRegistered = true;

                                    userCrud.LoadUserRoleCollection(ref user);
                                    user.UserRoleCollection.ForEach((userRole) => { userRoleCrud.LoadRole(ref userRole); });

                                    user.LastConnectionDate = DateTime.Now;
                                    userCrud.Save(ref user);
                                }
                            }
                        }

            if (!bIsRegistered)
            {
                user = null;
            }

            return(bIsRegistered);
        }
 public ProjectController(ProjectCrud project, UserCrud user)
 {
     _project = project;
     _user    = user;
 }
        public bool Create(IUserContext userContext, ref User user, out IList <TranslationEnum> errors)
        {
            bool withError = false;

            errors = new List <TranslationEnum>();

            using (var userCrud = new UserCrud(userContext))
                using (var roleCrud = new RoleCrud(userContext))
                {
                    // NOTE: if you have a compilation error on 'Role.CodeRefs.Member'
                    //       1. Change Role.CodeRefs.Member by ""
                    //       2. Add the [CodeRef = Member, Name = Member] entry in the 'Role' table
                    //       3. Compile the solution and execute LayerCake Generator
                    //       4. Then change back "" to Role.CodeRefs.Member

                    var memberRole = roleCrud.GetByCodeRef(Role.CodeRefs.Member);

                    if (user.UserRoleCollection.Count(l => l.IdRole == memberRole.Id) == 0)
                    {
                        user.UserRoleCollection.Add(new UserRole {
                            IdUser = user.Id, IdRole = memberRole.Id
                        });
                    }

                    user.RegistrationDate = DateTime.Now;

                    try
                    {
                        userCrud.Save(ref user, new SaveOptions {
                            SaveChildren = true
                        });

                        Task.WaitAll(SendMailOnUserCreatedAsync(user));                 // cannot use await because of ref/out parameters
                    }
                    catch (EntityValidationException evx)
                    {
                        withError = true;
                        errors    = evx.Translations;
                    }
                    catch (System.Net.Mail.SmtpFailedRecipientException)             // Cannot deliver the mail (bad email address?)
                    {
                        // NOTE: if you have a compilation error on 'TranslationEnum.CustomExceptionSmtpBadRecipient'
                        //       1. Comment the line
                        //       2. Add the 'CustomExceptionSmtpBadRecipient' entry in the 'Translation' table
                        //       3. Compile the solution
                        //       4. Execute LayerCake Generator Process (Menu > Extensions > Generate Translations)
                        //       5. Close LayerCake Generator
                        //       6. Then uncomment the line and recompile

                        withError = true;
                        errors.Add(TranslationEnum.CustomExceptionSmtpBadRecipient);
                    }
                    catch
                    {
                        withError = true;
                        throw;
                    }
                    finally
                    {
                        if (withError || errors.Count != 0)
                        {
                            if (user.IsInDb)
                            {
                                userCrud.Delete(user);                         // When the mail has not been delivered... (bad email address?)
                            }
                        }
                    }
                }

            return(!withError && errors.Count == 0);
        }
Example #21
0
 public UserController()
 {
     UserDetailsGetter = new UserCrud();
 }
Example #22
0
 public User GetUser(UserCrud userCrud)
 {
     return(userCrud.ReadOneById(userId));
 }
Example #23
0
 public CredidCardManager()
 {
     CrudFactory = new CredidCardCrud();
     UCrud       = new UserCrud();
 }
Example #24
0
 public ForumController(UserCrud user, ForumCrud forum)
 {
     _users = user;
     _forum = forum;
 }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LoginHandler"/> class.
 /// </summary>
 /// <param name="userCrud">The user crud.</param>
 public LoginHandler(UserCrud userCrud)
 {
     UserCrud = userCrud;
 }
Example #26
0
 public UserController(UserCrud users, LoginCrud login, SaltCrud salt)
 {
     _users = users;
     _login = login;
     _salt  = salt;
 }