Esempio n. 1
0
        public async Task <ServiceResponse <List <GetUserDto> > > AddUser(AddUserDto newUser)
        {
            ServiceResponse <List <GetUserDto> > serviceResponse = new ServiceResponse <List <GetUserDto> >();

            var user = _mapper.Map <User>(newUser);

            user.DateCreated = DateTime.Now.ToUniversalTime().ToString();
            Guid g = Guid.NewGuid();

            user.ActivateKey = g.ToString().Replace("-", "");
            //user.Password = BC.HashPassword(newUser.Password);
            user.PasswordHash = customPasswordHasher.HashPassword(newUser.Password);
            user.Status       = UserStatus.Disabled;

            try
            {
                await _context.Users.AddAsync(user);

                await _context.SaveChangesAsync();

                serviceResponse.Data = (_context.Users.Select(u => _mapper.Map <GetUserDto>(u))).ToList();
            }
            catch (System.Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.ToString();
            }

            return(serviceResponse);
        }
Esempio n. 2
0
        public void AddUser(User user)
        {
            getModifiedAttributes(user);

            user.Password = customPasswordHasher.HashPassword(user.Password);

            user.JoinDate = DateTime.Now;

            modelContext.Users.Add(user);
            modelContext.SaveChanges();
        }
        public async Task <IActionResult> ChangePassword([FromBody] Authenticate user)
        {
            if (user == null)
            {
                return(BadRequest(StaticVar.MessageNotFound));
            }
            //get user from DB
            UserTest dbUser = await _serviceUserTest.GetByIDAsync(user.Code).ConfigureAwait(false);

            if (dbUser == null)
            {
                return(BadRequest(StaticVar.MessageNotFound));
            }
            //kiểm tra password cũ có đúng không
            if (CustomPasswordHasher.VerifyPassword(dbUser.Password, user.OldPassword))
            {
                var passwordHashed = CustomPasswordHasher.HashPassword(user.Password);
                //đúng thì cho đổi password
                BsonDocument objBSON = new BsonDocument
                {
                    { "Password", passwordHashed }
                };
                await _serviceUserTest.UpdateCustomizeFieldByIdAsync(dbUser.Id, objBSON);

                return(Ok("Đổi password thành công"));
            }
            else
            {
                //sai thì báo lỗi
                return(BadRequest("User hoặc mật khẩu cũ không hợp lệ"));
            }
        }
Esempio n. 4
0
        public IActionResult Register(AccountRegister new_user)
        {
            using (GlobalDBContext _context = new GlobalDBContext())
            {
                string _domainurl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";
                // ->TODO Validation check on clinet side using Jquery or JavaScript

                // Password hashed with extra layer of security
                string password          = new_user.Password;
                CustomPasswordHasher pwd = new CustomPasswordHasher();
                // increse the size to increase secuirty but lower performance
                string salt   = pwd.CreateSalt(10);
                string hashed = pwd.HashPassword(password, salt);
                //new_user.Salt = salt;
                new_user.Password = hashed;
                // var errors = ModelState.Values.SelectMany(v => v.Errors);
                Role role    = _context.Roles.Find(new_user.UserRole);
                User theUser = new User();
                theUser.AddFromAccountRegsiter(new_user, role, salt);
                string uniqueToken = Guid.NewGuid().ToString("N").Substring(0, 6);
                theUser.UniqueToken = uniqueToken;
                _context.Users.Add(theUser);

                SendEmail email    = new SendEmail(_emailSettings);
                string    fullname = theUser.UserFirstName + " " + theUser.UserLastName;
                string    msg      = "Please verify you email account for the verification. Click on the link to verify :";
                msg += _domainurl + "/Account/ConfirmEmail?email=" + theUser.UserEmail + "&token=" + theUser.UniqueToken;

                _context.SaveChanges();
                email.SendEmailtoUser(fullname, theUser.UserEmail, "Email Verification", msg);
                ViewBag.Messsage = new_user.FirstName + " " + new_user.LastName + " successfully registered. A Email has been sent for the verfication.";
            }
            return(View());
        }
Esempio n. 5
0
        /// <summary>
        /// validates password and saves it in DB
        /// </summary>
        /// <param name="resetPasswordInfo"></param>
        /// <returns></returns>
        public ValidationViewModel ValidateForgotPassword(UserLoginViewModel resetPasswordInfo)
        {
            ValidationViewModel response = new ValidationViewModel();

            try
            {
                if (!(string.IsNullOrEmpty(resetPasswordInfo.UserId) && string.IsNullOrEmpty(resetPasswordInfo.ForgotPasswordToken)))
                {
                    string userID = resetPasswordInfo.UserId;

                    UserLoginViewModel user = GetUserDetails(userID);

                    if (user != null && user.ForgotPasswordToken != null && user.ForgotPasswordToken.Equals(resetPasswordInfo.ForgotPasswordToken))
                    {
                        if (user.Password == null || !(user.Password.Equals(resetPasswordInfo.Password)))
                        {
                            CustomPasswordHasher customPasswordHasher = new CustomPasswordHasher();
                            user.Password            = customPasswordHasher.HashPassword(resetPasswordInfo.Password);
                            user.ForgotPasswordToken = null;
                            user.LastPasswordChanged = DateTime.Now;
                            if (UpdatePassword(user).Success)
                            {
                                response.Success        = true;
                                response.SuccessMessage = BusinessConstants.PASSWORD_SAVED;
                                return(response);
                            }
                        }
                        response.Success = false;
                        response.ErrorMessages.Add(BusinessConstants.CANNOT_REUSE_PASSWORD);
                        return(response);
                    }
                    else if (user != null && user.ForgotPasswordToken == null)
                    {
                        response.Success = false;
                        response.ErrorMessages.Add(BusinessConstants.LINK_EXPIRED);
                        return(response);
                    }
                    response.Success = false;
                    response.ErrorMessages.Add(BusinessConstants.CHANGE_IN_URL);
                    return(response);
                }
                response.ErrorMessages.Add(BusinessConstants.EMAIL_IS_EMPTY);
                response.Success = false;
            }
            catch (Exception ex)
            {
                _logger.Log(ex, LogLevel.Error, ex.Message);
                response.ErrorMessages.Add(BusinessConstants.ERROR_OCCURED);
                response.Success = false;
            }
            return(response);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string password = "******";

            IdentityUser         user   = new IdentityUser();
            CustomPasswordHasher hasher = new CustomPasswordHasher();

            string hashedValue = hasher.HashPassword(user, password);

            Console.WriteLine("HashedValue > " + hashedValue);

            Console.WriteLine("Verify > " + hasher.VerifyHashedPassword(user, hashedValue, password));
        }
        public ActionResult Create([Bind(Include = "Id,UserName,Password,FullName")] ApplicationUser applicationUser)
        {
            if (ModelState.IsValid)
            {
                CustomPasswordHasher customPasswordHasher = new CustomPasswordHasher();
                string hashedPassword = customPasswordHasher.HashPassword(applicationUser.Password);
                applicationUser.Password = hashedPassword;

                db.ApplicationUsers.Add(applicationUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(applicationUser));
        }
        public async Task <ActionResult <UserTest> > Post([FromBody] UserTest data)
        {
            try
            {
                data.Code = data.Code.ToLower().Trim();
                if (!String.IsNullOrEmpty(data.Email))
                {
                    data.Email = data.Email.ToLower()?.Trim();
                }
                data.Password  = CustomPasswordHasher.HashPassword(data.Password);
                data.CreatedOn = DateTime.Now;
                //data.CreatedBy = UserClaim.UserId;

                return(await _serviceUserTest.InsertAsync(data));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        public HttpResponseMessage RegisterNewUser(string LoginType, string UserName, string Name, string ProfilePictureURL, string Password, string MobilePlatform, string PushNotificationID,
                                                   string Country, string Region, string City)
        {
            PenYourPrayerUser user = new PenYourPrayerUser();

            user.LoginType          = LoginType;
            user.UserName           = UserName.Trim();
            user.DisplayName        = Name.Trim();
            user.ProfilePictureURL  = ProfilePictureURL;
            user.Password           = CustomPasswordHasher.HashPassword(Password);
            user.MobilePlatform     = MobilePlatform;
            user.PushNotificationID = PushNotificationID;
            user.City    = City;
            user.Region  = Region;
            user.Country = Country;

            using (DBDataContext db = new DBDataContext())
            {
                string result           = "";
                string HMACSecretKey    = CustomPasswordHasher.HashPassword(Guid.NewGuid().ToString()) + CustomPasswordHasher.HashPassword(Guid.NewGuid().ToString());
                long?  id               = -1;
                string verificationCode = "";
                db.usp_AddNewUser(user.LoginType, user.UserName, user.DisplayName, user.ProfilePictureURL, user.Password, user.MobilePlatform, user.PushNotificationID, HMACSecretKey, user.Country, user.Region, user.City, ref result, ref id, ref verificationCode);
                user.ID = (long)id;

                if (result.ToUpper() != "OK")
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, new CustomResponseMessage()
                    {
                        StatusCode = (int)HttpStatusCode.BadRequest, Description = result
                    }));
                }
                //send email to verify email address.
                CommonMethod.sendAccountActiviationEmail(user.UserName, user.DisplayName, verificationCode, user.ID.ToString());
                return(Request.CreateResponse(HttpStatusCode.OK, new CustomResponseMessage()
                {
                    StatusCode = (int)HttpStatusCode.OK
                }));
            }
        }
Esempio n. 10
0
        public async Task <ServiceResponse <int> > Register(User user, string password)
        {
            ServiceResponse <int> response = new ServiceResponse <int>();

            if (await UserExists(user.Name))
            {
                response.Success = false;
                response.Message = "User already exists.";
                return(response);
            }

            user.PasswordHash = customPasswordHasher.HashPassword(password);
            user.DateCreated  = DateTime.Now.ToUniversalTime().ToString();
            Guid g = Guid.NewGuid();

            user.ActivateKey = g.ToString().Replace("-", "");
            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            response.Data = user.Id;
            return(response);
        }
Esempio n. 11
0
        public IActionResult Login(AccountLogin user)
        {
            using (GlobalDBContext _context = new GlobalDBContext())
            {
                //var userA = _context.Users.ToList<User>();
                User theUser = _context.Users.Include(p => p.Role).FirstOrDefault(u => u.UserEmail == user.Email);
                // Check if the user with email exists
                if (theUser != null)
                {
                    //Check email is verified
                    if (theUser.UserEmailVerified == false)
                    {
                        ModelState.AddModelError("", "Email is not verifed you cant login.");
                        return(View());
                    }
                    CustomPasswordHasher pwd = new CustomPasswordHasher();
                    string hashed            = pwd.HashPassword(user.Password, theUser.Salt);
                    // Check if the user entered password is correct
                    if (hashed == theUser.UserPassword)
                    {
                        //string usr = JsonConvert.SerializeObject(theUser, Formatting.Indented, new JsonSerializerSettings()
                        //{
                        //    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                        //});

                        // Custom Auth Token

                        var token = _auth.Authenticate(theUser.UserEmail, theUser.Role.RoleName, theUser.UserId);
                        // Create Sessions
                        //HttpContext.Session.SetString("UserSession", usr);
                        HttpContext.Session.SetString("UserToken", token);

                        // Delete Existing cookie
                        Response.Cookies.Delete("UserToken");
                        //Create Cookie
                        if (user.RememberMe)
                        {
                            CookieOptions cookieOptions = new CookieOptions();
                            cookieOptions.Expires = DateTime.Now.AddDays(7);
                            Response.Cookies.Append("UserToken", token, cookieOptions);
                        }

                        // at Genearted token in header
                        using (var client = new HttpClient())
                        {
                            client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
                        }
                        if (TempData.ContainsKey("redirect"))
                        {
                            string redirectUrl = TempData["redirect"].ToString();
                            string fullPath    = host + "/" + redirectUrl;
                            return(Redirect(fullPath));
                        }

                        // Id 1 for Student & Id 2 for Employer
                        if (theUser.Role.RoleId == 1)
                        {
                            // Student
                            return(RedirectToAction("Index", "DashboardStudent"));
                        }
                        if (theUser.Role.RoleId == 2)
                        {
                            // Employer
                            return(RedirectToAction("Index", "DashboardEmployer"));
                        }
                        if (theUser.Role.RoleId == 3)
                        {
                            // Teacher
                            return(RedirectToAction("Index", "DashboardTeacher"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Wrong Credentials.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "No user exists with the given email.");
                    ModelState.AddModelError("", "Wrong Credentials.");
                }

                return(View());
            }
        }
        public HttpResponseMessage SocialLogin(string LoginType, string UserName, string Secret, string AccessToken, string PushNotificationID, string MobilePlatform)
        {
            bool              socialresult = false;
            object            token        = null;
            PenYourPrayerUser tuser        = new PenYourPrayerUser();

            if (LoginType.ToUpper() == "FACEBOOK")
            {
                socialresult = SocialMediaAuthentication.CheckFacebookAccessToken(AccessToken, ref token);
                if (socialresult)
                {
                    FacebookDebugToken fbtoken = (FacebookDebugToken)token;
                    tuser.ProfilePictureURL = fbtoken.data.usertoken.picture.data.url;
                    tuser.DisplayName       = fbtoken.data.usertoken.name;
                    tuser.UserName          = fbtoken.data.usertoken.email;
                }
            }
            //else if (LoginType.ToUpper() == "TWITTER")
            //{
            //    result = SocialMediaAuthentication.checkTwitterAccessToken(UserName, "806837785-trTr0ObdqaW0owy1N0WXJFh6OGSlgUH74nh3qoHO", "w5j7WPwHWwY4DSfJ82tRVZF7SBogZJ6XABptVt431uOowvwFKC");
            //}
            else if (LoginType.ToUpper() == "GOOGLEPLUS")
            {
                socialresult = SocialMediaAuthentication.CheckGooglePlusAccessToken(AccessToken, ref token);
                if (socialresult)
                {
                    GoogleTokenInfo gptoken = (GoogleTokenInfo)token;
                    tuser.ProfilePictureURL = gptoken.picture;
                    tuser.DisplayName       = gptoken.name;
                    tuser.UserName          = gptoken.email;
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new CustomResponseMessage()
                {
                    StatusCode = (int)HttpStatusCode.BadRequest, Description = "Invalid Social Login"
                }));
            }


            if (!socialresult)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new CustomResponseMessage()
                {
                    StatusCode = (int)HttpStatusCode.BadRequest, Description = "Invalid Social Login"
                }));
            }
            else
            {
                using (DBDataContext db = new DBDataContext())
                {
                    PenYourPrayerUser user;
                    List <usp_GetUserInformationResult> res = db.usp_GetUserInformation(LoginType, UserName).ToList();
                    if (res.Count() > 0)
                    {
                        usp_GetUserInformationResult t = res.ElementAt(0);
                        db.usp_UpdateUserMobileDeviceInformation(t.ID, MobilePlatform, PushNotificationID);
                        db.usp_UpdateUserSocialInformation(t.ID, tuser.DisplayName, tuser.UserName, tuser.ProfilePictureURL);

                        user                    = new PenYourPrayerUser();
                        user.ID                 = t.ID;
                        user.DisplayName        = tuser.DisplayName;
                        user.LoginType          = t.LoginType;
                        user.UserName           = t.UserName;
                        user.MobilePlatform     = MobilePlatform;
                        user.ProfilePictureURL  = tuser.ProfilePictureURL;
                        user.PushNotificationID = PushNotificationID;
                        user.HMACHashKey        = t.HMACHashKey;
                        user.EmailVerification  = true;
                    }
                    else
                    {
                        //create new account
                        string result           = "";
                        string verificationCode = "";
                        long?  id            = -1;
                        string HMACSecretKey = CustomPasswordHasher.HashPassword(Guid.NewGuid().ToString()) + CustomPasswordHasher.HashPassword(Guid.NewGuid().ToString());
                        db.usp_AddNewUser(LoginType, UserName, tuser.DisplayName, tuser.ProfilePictureURL, "", MobilePlatform, PushNotificationID, HMACSecretKey, null, null, null, ref result, ref id, ref verificationCode);

                        user                    = new PenYourPrayerUser();
                        user.ID                 = (long)id;
                        user.DisplayName        = tuser.DisplayName;
                        user.LoginType          = LoginType;
                        user.UserName           = UserName;
                        user.MobilePlatform     = MobilePlatform;
                        user.ProfilePictureURL  = tuser.ProfilePictureURL;
                        user.PushNotificationID = PushNotificationID;
                        user.HMACHashKey        = HMACSecretKey;
                        user.EmailVerification  = true;
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, user));
                }
            }
        }
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "CarMakes",
                columns: table => new
            {
                MakeId = table.Column <int>(nullable: false)
                         .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                Make        = table.Column <string>(nullable: true),
                CountryCode = table.Column <string>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_CarMakes", x => x.MakeId);
            });

            migrationBuilder.CreateTable(
                name: "Clubs",
                columns: table => new
            {
                ClubId = table.Column <int>(nullable: false)
                         .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                Name        = table.Column <string>(nullable: true),
                Description = table.Column <string>(nullable: true),
                Photo       = table.Column <string>(nullable: true),
                Contact     = table.Column <string>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Clubs", x => x.ClubId);
            });

            migrationBuilder.CreateTable(
                name: "EventTypes",
                columns: table => new
            {
                EventTypeId = table.Column <int>(nullable: false)
                              .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                Type = table.Column <int>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_EventTypes", x => x.EventTypeId);
            });

            migrationBuilder.CreateTable(
                name: "Lowerings",
                columns: table => new
            {
                LoweringId = table.Column <int>(nullable: false)
                             .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                Type = table.Column <int>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Lowerings", x => x.LoweringId);
            });

            migrationBuilder.CreateTable(
                name: "Events",
                columns: table => new
            {
                EventId = table.Column <int>(nullable: false)
                          .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                Name        = table.Column <string>(nullable: false),
                Description = table.Column <string>(nullable: false),
                Location    = table.Column <string>(nullable: false),
                Capacity    = table.Column <int>(nullable: false),
                EventTypeId = table.Column <int>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Events", x => x.EventId);
                table.ForeignKey(
                    name: "FK_Events_EventTypes_EventTypeId",
                    column: x => x.EventTypeId,
                    principalTable: "EventTypes",
                    principalColumn: "EventTypeId",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "Cars",
                columns: table => new
            {
                CarId = table.Column <int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                MakeId         = table.Column <int>(nullable: false),
                Model          = table.Column <string>(nullable: true),
                ProductionYear = table.Column <int>(nullable: false),
                Displacement   = table.Column <string>(nullable: true),
                LoweringId     = table.Column <int>(nullable: false),
                Wheels         = table.Column <string>(nullable: true),
                MemberId       = table.Column <int>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Cars", x => x.CarId);
                table.ForeignKey(
                    name: "FK_Cars_Lowerings_LoweringId",
                    column: x => x.LoweringId,
                    principalTable: "Lowerings",
                    principalColumn: "LoweringId",
                    onDelete: ReferentialAction.Cascade);
                table.ForeignKey(
                    name: "FK_Cars_CarMakes_MakeId",
                    column: x => x.MakeId,
                    principalTable: "CarMakes",
                    principalColumn: "MakeId",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "Members",
                columns: table => new
            {
                MemberId = table.Column <int>(nullable: false)
                           .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                Name         = table.Column <string>(nullable: false),
                Surname      = table.Column <string>(nullable: false),
                DateOfBirth  = table.Column <DateTime>(nullable: false),
                PostalCode   = table.Column <string>(nullable: false),
                City         = table.Column <string>(nullable: false),
                Email        = table.Column <string>(nullable: false),
                Username     = table.Column <string>(nullable: false),
                PasswordHash = table.Column <string>(nullable: true),
                PasswordSalt = table.Column <string>(nullable: true),
                CarId        = table.Column <int>(nullable: false),
                ClubId       = table.Column <int>(nullable: false),
                CarId1       = table.Column <int>(nullable: true)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Members", x => x.MemberId);
                table.ForeignKey(
                    name: "FK_Members_Cars_CarId1",
                    column: x => x.CarId1,
                    principalTable: "Cars",
                    principalColumn: "CarId",
                    onDelete: ReferentialAction.Restrict);
                table.ForeignKey(
                    name: "FK_Members_Clubs_ClubId",
                    column: x => x.ClubId,
                    principalTable: "Clubs",
                    principalColumn: "ClubId",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateTable(
                name: "Registrations",
                columns: table => new
            {
                RegistrationId = table.Column <int>(nullable: false)
                                 .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                MemberId = table.Column <int>(nullable: false),
                EventId  = table.Column <int>(nullable: false)
            },
                constraints: table =>
            {
                table.PrimaryKey("PK_Registrations", x => x.RegistrationId);
                table.ForeignKey(
                    name: "FK_Registrations_Events_EventId",
                    column: x => x.EventId,
                    principalTable: "Events",
                    principalColumn: "EventId",
                    onDelete: ReferentialAction.Cascade);
                table.ForeignKey(
                    name: "FK_Registrations_Members_MemberId",
                    column: x => x.MemberId,
                    principalTable: "Members",
                    principalColumn: "MemberId",
                    onDelete: ReferentialAction.Cascade);
            });

            migrationBuilder.CreateIndex(
                name: "IX_Cars_LoweringId",
                table: "Cars",
                column: "LoweringId");

            migrationBuilder.CreateIndex(
                name: "IX_Cars_MakeId",
                table: "Cars",
                column: "MakeId");

            migrationBuilder.CreateIndex(
                name: "IX_Events_EventTypeId",
                table: "Events",
                column: "EventTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_Members_CarId1",
                table: "Members",
                column: "CarId1");

            migrationBuilder.CreateIndex(
                name: "IX_Members_ClubId",
                table: "Members",
                column: "ClubId");

            migrationBuilder.CreateIndex(
                name: "IX_Registrations_EventId",
                table: "Registrations",
                column: "EventId");

            migrationBuilder.CreateIndex(
                name: "IX_Registrations_MemberId",
                table: "Registrations",
                column: "MemberId");


            //EventTypes
            migrationBuilder.InsertData(
                table: "EventTypes",
                columns: new[] { "EventTypeId", "Type" },
                values: new object[] { 1, 1 });
            migrationBuilder.InsertData(
                table: "EventTypes",
                columns: new[] { "EventTypeId", "Type" },
                values: new object[] { 2, 2 });
            migrationBuilder.InsertData(
                table: "EventTypes",
                columns: new[] { "EventTypeId", "Type" },
                values: new object[] { 3, 3 });
            migrationBuilder.InsertData(
                table: "EventTypes",
                columns: new[] { "EventTypeId", "Type" },
                values: new object[] { 4, 4 });
            migrationBuilder.InsertData(
                table: "EventTypes",
                columns: new[] { "EventTypeId", "Type" },
                values: new object[] { 5, 5 });

            //Lowerings
            migrationBuilder.InsertData(
                table: "Lowerings",
                columns: new[] { "LoweringId", "Type" },
                values: new object[] { 1, 1 });
            migrationBuilder.InsertData(
                table: "Lowerings",
                columns: new[] { "LoweringId", "Type" },
                values: new object[] { 2, 2 });
            migrationBuilder.InsertData(
                table: "Lowerings",
                columns: new[] { "LoweringId", "Type" },
                values: new object[] { 3, 3 });
            migrationBuilder.InsertData(
                table: "Lowerings",
                columns: new[] { "LoweringId", "Type" },
                values: new object[] { 4, 4 });

            //CarMakes
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 1, "BMW", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 2, "Audi", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 3, "Mercedes", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 4, "Porsche", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 5, "Volkswagen", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 6, "Opel", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 7, "Mazda", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 8, "Mitsubishi", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 9, "Honda", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 10, "Subaru", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 11, "Toyota", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 12, "Suzuki", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 13, "Nissan", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 14, "Daihatsu", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 15, "Abarth", "ITA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 16, "AC", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 17, "Acura", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 18, "Alfa Romeo", "ITA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 19, "Aston Martin", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 20, "Bently", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 21, "Bugatti", "FRA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 22, "Buick", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 23, "Cadillac", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 24, "Chevrolet", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 25, "Citroën", "FRA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 26, "Chrysler", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 27, "Datsun", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 28, "Dodge", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 29, "Ferrari", "ITA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 30, "Fiat", "ITA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 31, "Ford", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 32, "Genesis", "KOR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 33, "GMC", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 34, "Holden", "AUS" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 35, "Hyundai", "KOR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 36, "Infinity", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 37, "Jaguar", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 38, "Jeep", "ITA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 39, "Koenigsegg", "SWE" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 40, "Kia", "KOR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 41, "Lamborghini", "ITA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 42, "Land Rover", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 43, "Lexus", "JAP" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 44, "Lincoln", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 45, "Lotus", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 46, "Maserati", "ITA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 47, "McLaren", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 48, "MG", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 49, "Mini", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 50, "Peugot", "FRA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 51, "Plymouth", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 52, "Renault", "FRA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 53, "Rolls-Royce", "GBR" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 54, "Seat", "SPA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 55, "Smart", "GER" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 56, "Tesla", "USA" });
            migrationBuilder.InsertData(
                table: "CarMakes",
                columns: new[] { "MakeID", "Make", "CountryCode" },
                values: new object[] { 57, "Volvo", "SWE" });
            //Cars
            migrationBuilder.InsertData(
                table: "Cars",
                columns: new[] { "CarId", "MakeId", "Model", "ProductionYear", "Displacement", "LoweringId", "Wheels", "MemberId" },
                values: new object[] { 1, 7, "3",
                                       "2015", "2000 cc", 3,
                                       "asa TEC GT7 19\"", 1 });

            //Clubs
            migrationBuilder.InsertData(
                table: "Clubs",
                columns: new[] { "ClubId", "Name", "Description", "Photo", "Contact" },
                values: new object[] { 1, "MazdaClubBelgium", "Club uit België, alle modellen binnen mazda zijn toegelaten.",
                                       "no photo", "*****@*****.**" });
            migrationBuilder.InsertData(
                table: "Clubs",
                columns: new[] { "ClubId", "Name", "Description", "Photo", "Contact" },
                values: new object[] { 2, "DuitseOldtimer", "Club voor duitse oldtimers.", "no photo", "*****@*****.**" });

            //Members
            CustomPasswordHasher ph = new CustomPasswordHasher();

            string salt = ph.GetSalt();

            migrationBuilder.InsertData(
                table: "Members",
                columns: new[] { "MemberId", "Name", "Surname", "DateOfBirth", "PostalCode", "City", "Email", "Username", "PasswordHash", "PasswordSalt", "CarId", "ClubId" },
                values: new object[] { 1, "Gert", "Scheers",
                                       DateTime.Parse("1994-11-17").Date, "3920", "Lommel",
                                       "*****@*****.**", "gert.scheers", ph.HashPassword("test", salt), salt, 1, 1 });
            //REDO ph.GetSalt() for every new user to create different salts

            //Events
            migrationBuilder.InsertData(
                table: "Events",
                columns: new[] { "EventId", "Name", "Description", "Location", "Capacity", "EventTypeId" },
                values: new object[] { 1, "Japfest", "Meeting op Circuit Zandvoort, enkel voor Japanse auto's en brommers.",
                                       "Zandvoort", 1500, 1 });
            migrationBuilder.InsertData(
                table: "Events",
                columns: new[] { "EventId", "Name", "Description", "Location", "Capacity", "EventTypeId" },
                values: new object[] { 2, "Germanized", "Meeting voor Duitse merken.", "Hechtel", 500, 2 });
        }
Esempio n. 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="objUser"></param>
 /// <returns></returns>
 public async Task CreateWifiUser(User objUser)
 {
     string Password = CustomPasswordHasher.HashPassword(objUser.PasswordHash);
     await UserManager.CreateAsync(objUser, Password);
 }
Esempio n. 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="SiteId"></param>
        public bool IsAuthenticatedMemberWithCredential(string UserName, string Password, int SiteId)
        {
            string hashPassword = CustomPasswordHasher.HashPassword(Password);

            return(db.Users.Any(m => m.UserName == UserName && m.PasswordHash == hashPassword));
        }
Esempio n. 16
0
        public IActionResult Login(AccountLogin user)
        {
            using (GlobalDBContext _context = new GlobalDBContext())
            {
                //var userA = _context.Users.ToList<User>();
                User theUser = _context.Users.Include(p => p.Role).FirstOrDefault(u => u.UserEmail == user.Email);
                // Check if the user with email exists
                if (theUser != null)
                {
                    CustomPasswordHasher pwd = new CustomPasswordHasher();
                    string hashed            = pwd.HashPassword(user.Password, theUser.Salt);
                    // Check if the user entered password is correct
                    if (hashed == theUser.UserPassword)
                    {
                        string usr = JsonConvert.SerializeObject(theUser, Formatting.Indented,
                                                                 new JsonSerializerSettings()
                        {
                            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                        });

                        // Custom Auth Token
                        var token = _auth.Authenticate(theUser.UserEmail, theUser.Role.RoleName);
                        // set Sessions
                        HttpContext.Session.SetString("UserSession", usr);
                        HttpContext.Session.SetString("UserToken", "Bearer " + token);

                        using (var client = new HttpClient())
                        {
                            client.DefaultRequestHeaders.Add("Authorization", token);
                        }

                        //Request.Headers.Add()
                        if (token == null)
                        {
                            return(Unauthorized());
                        }

                        // Id 1 for Student & Id 2 for Employer
                        if (theUser.Role.RoleId == 1)
                        {
                            // Student
                            return(RedirectToAction("Index", "DashboardStudent"));
                        }
                        if (theUser.Role.RoleId == 2)
                        {
                            // Employer
                            return(RedirectToAction("Index", "DashboardEmployer"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Wrong Credentials.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "No user exists with the given email.");
                    ModelState.AddModelError("", "Wrong Credentials.");
                }

                return(View());
            }
        }