Example #1
0
        public IActionResult Register(Dictionary <string, string> profile)
        {
            Models.Security    security   = new Models.Security();
            DatabaseConnection connection = new DatabaseConnection();

            try
            {
                if (CheckCredentials(profile))
                {
                    connection.AddUserToDatabase(profile["email"], security.Encrypt(profile["password"]));

                    ConcreteOwnerBuilder ownerBuilder = new ConcreteOwnerBuilder();
                    ownerBuilder.AddEmail(profile["email"]);
                    ownerBuilder.AddFirstName(profile["firstName"]);
                    ownerBuilder.AddSecondName(profile["secondName"]);
                    Random random = new Random();
                    ownerBuilder.AddID(random.Next(100, 999));

                    connection.AddOwnerToDatabase(ownerBuilder.BuildOwner());
                    return(new StatusCodeResult(StatusCodes.Status201Created));
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (SqlException)
            {
                return(new StatusCodeResult(StatusCodes.Status409Conflict));
            }
            catch (Exception)
            {
                return(new StatusCodeResult(StatusCodes.Status400BadRequest));
            }
        }
Example #2
0
            public Session(string email)
            {
                var user = databaseConnection.GetOwnerDataByEmail(email);
                ConcreteOwnerBuilder concreteOwnerBuilder = new ConcreteOwnerBuilder();

                concreteOwnerBuilder.AddFirstName(user["FirstName"]);
                concreteOwnerBuilder.AddSecondName(user["Secondname"]);
                concreteOwnerBuilder.AddEmail(user["Email"]);
                concreteOwnerBuilder.AddID(int.Parse(user["IdNumber"]));
                User  = concreteOwnerBuilder.BuildOwner();
                Start = DateTime.Now;
                ProlongueSession();
                var random = new Random();

                SessionKey = random.Next(10, 99).ToString()
                             + (char)('a' + random.Next(1, 26))
                             + (char)('a' + random.Next(1, 26))
                             + random.Next(101, 999)
                             + (char)('a' + random.Next(1, 26))
                             + (char)('a' + random.Next(1, 26))
                             + random.Next(10, 99);
            }