Exemple #1
0
 public ActionResult SendRecoveryMail(ForgotPasswordModel forgotPasswordModel)
 {
     try
     {
         User   u = DataAccessAction.user.GetUserByMail(forgotPasswordModel.Mail);
         String s = PasswordGenerate.AleaPassword();
         u.Password = s;
         String address = u.Mail.Trim();
         DataAccessAction.user.UpdateUser(u);
         MailMessage email = new MailMessage();
         email.From = new System.Net.Mail.MailAddress("*****@*****.**");
         email.To.Add(new MailAddress(address));
         email.IsBodyHtml = true;
         email.Subject    = "Platine - New Password";
         email.Body       = " voici votre nouveau mot de passe : " + s;
         System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
         smtp.Host        = "smtp.sfr.fr";
         smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "ohdrrsqq");
         smtp.Send(email);
     }
     catch (PlatineException ex)
     {
         ViewBag.Message = ex.Message;
         return(View("ForgotPassword"));
     }
     catch (UserException ue)
     {
         ViewBag.Message = ue.Message;
         return(View("ForgotPassword"));
     }
     return(Redirect("/"));
 }
        protected void BtnPasswordGenerate_Click(object sender, EventArgs e)
        {
            PasswordGeneratorRequest request = new PasswordGeneratorRequest();

            request.MinLength         = int.Parse(txtMinLength.Text);
            request.MaxLength         = int.Parse(txtMaxLength.Text);
            request.IsUpperChars      = chkUpperChars.Checked;
            request.IsLowerChars      = chkLowerChars.Checked;
            request.IsNumberChars     = chkNumberChars.Checked;
            request.IsSpecialChars    = chkSpecialChars.Checked;
            request.AllowChars        = txtAllowChars.Text.Trim();
            request.DenyChars         = txtDenyChars.Text.Trim();
            txtGeneratedPassword.Text = PasswordGenerate.CreateRandomPassword(request);
        }
        /// <summary>
        /// Register
        /// </summary>
        /// <param name="user">Model User</param>
        /// <param name="password">Password</param>
        public async Task <User> Register(User user, string password)
        {
            user.Created = DateTime.Now;
            byte[]           passwordHash, passwordSalt;
            PasswordGenerate passwordGenerate = new PasswordGenerate();

            passwordGenerate.CreatePasswordHash(password, out passwordHash, out passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Exemple #4
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    Role role = new Role();
                    // добавляем пользователя в бд
                    if (User.IsInRole("Admin"))
                    {
                        role = db.Roles.Find(model.RoleId);
                    }
                    else
                    {
                        role = await db.Roles.FirstOrDefaultAsync(r => r.RoleName == "User");
                    }

                    user = new User
                    {
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        Email     = model.Email,
                        Password  = PasswordGenerate.HashPassword(model.Password),
                        Role      = role ?? null
                    };
                    db.Users.Add(user);
                    await db.SaveChangesAsync();

                    await Authenticate(user); // аутентификация

                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    ModelState.AddModelError("", "Такой пользователь уже существует");
                }
            }


            return(View(model));
        }
Exemple #5
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.Include(u => u.Role).
                            FirstOrDefaultAsync(u => u.Email == model.Email &&
                                                u.Password == PasswordGenerate.HashPassword(model.Password));

                if (user != null)
                {
                    await Authenticate(user); // аутентификация

                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError("", "Некорректные логин и(или) пароль");
            }

            return(View(model));
        }
Exemple #6
0
        public ApiResponse <User> ValidCredentials(User userRequest, User userReponse)
        {
            var apiResponse = new ApiResponse <User>();

            if (userReponse == null)
            {
                apiResponse.Message    = "Usuário e/ou senha inválidos";
                apiResponse.IsSuccess  = false;
                apiResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
            }
            else if (PasswordGenerate.Dencryption(userRequest.Password) != PasswordGenerate.Dencryption(userReponse.Password))
            {
                apiResponse.Message    = "Usuário e/ou senha inválidos";
                apiResponse.IsSuccess  = false;
                apiResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
            }

            return(apiResponse);
        }
Exemple #7
0
        public void UpdateUser()
        {
            var userInfo = new User()
            {
                Email = "*****@*****.**", IsFacebookUser = false, AcceptedTerms = true, Name = "Kenji"
            };

            userInfo.GuidKey = GuidGenerate.USER_ID;
            var userClient = new UserClient();

            var apiResponse = userClient.GetByObj(userInfo);

            if (apiResponse.IsSuccess)
            {
                userInfo.Password = PasswordGenerate.Encryption("321");
                apiResponse       = userClient.Update(userInfo);
            }

            Assert.IsTrue(apiResponse.IsSuccess);
        }
        /// <summary>
        /// Seed User
        /// </summary>
        /// <remarks>
        /// Code in comment don't compile, so the solution for unique data is comment this method in Startup.cs
        /// </remarks>
        public void SeedUsers()
        {
            var userData = System.IO.File.ReadAllText("Data/Seed/UsersSeedData.json");
            var users    = JsonConvert.DeserializeObject <List <User> >(userData);

            foreach (var user in users)
            {
                if (!_context.Users.Any(x => x.Username == user.Username))
                {
                    PasswordGenerate passwordGenerate = new PasswordGenerate();
                    passwordGenerate.CreatePasswordHash("password", out byte[] passwordHash, out byte[] passwordSalt);

                    user.PasswordHash = passwordHash;
                    user.PasswordSalt = passwordSalt;
                    user.Username     = user.Username.ToLower();

                    _context.Users.Add(user);
                }
            }
            _context.SaveChanges();
        }
Exemple #9
0
        static void Main(string[] args)
        {
            try
            {
                var userClient = new UserClient();

                var userInfo1 = new User()
                {
                    Email = "*****@*****.**", IsFacebookUser = false, AcceptedTerms = true, Password = PasswordGenerate.Encryption("321")
                };
                userInfo1.GuidKey = GuidGenerate.USER_ID;
                var apiResponse = userClient.Login(userInfo1);
                if (!apiResponse.IsSuccess)
                {
                    return;
                }

                // user insert
                var userInfo = new User()
                {
                    Email = "*****@*****.**", IsFacebookUser = false, AcceptedTerms = true, Name = "alvin", Password = PasswordGenerate.Encryption("123456")
                };
                apiResponse = userClient.Add(userInfo);
                if (!apiResponse.IsSuccess)
                {
                    return;
                }

                // teste get
                apiResponse = userClient.GetByObj(userInfo);
                var userGet = apiResponse.Data;

                userGet.Name = "Alvin Rezende";
                apiResponse  = userClient.Update(userGet);

                // account add
                var accountClient = new AccountClient();
                var accountInfo   = new Account()
                {
                    User = userInfo, Birthday = DateTime.Now, City = "Patrocínio", GamerTag = "@rezenboy", State = "SP", StartingDate = DateTime.Now
                };
                var apiResponseAccount = accountClient.Add(accountInfo);
                if (!apiResponseAccount.IsSuccess)
                {
                    return;
                }

                // teste update
                if (apiResponseAccount.IsSuccess)
                {
                    accountInfo.FavorityGame = Raise.Enums.Games.COD;
                    apiResponseAccount       = accountClient.Update(accountInfo);
                }

                // teste get feed
                //if (apiResponseAccount.IsSuccess)
                //{
                //    var feedClient = new FeedClient();
                //    var feedInfo = new Feed() { GuidKey = GuidGenerate.USER_ID };
                //    var lst = feedClient.GetByObj(feedInfo);
                //}

                apiResponse = userClient.GetAll();
            }
            catch (Exception exc)
            {
            }
        }
        public async Task <ActionResult> Register(AccIndexer model)
        {
            var psd = "put your password here";

            if (ModelState.IsValid)
            {
                var glCategory = _content.acctIndex.SingleOrDefault(m => m.id == 20);
                var till       = new TillGenerate().GetTillCode(glCategory.accountCode);
                if (model.reg.role == "Plain User")
                {
                    till = String.Empty;
                }
                var password = new PasswordGenerate().GetNewPassword();

                model.reg.Password        = password + "&zA1";
                model.reg.ConfirmPassword = password + "&zA1";
                var tempLocation      = _content.stat.SingleOrDefault(m => m.id == 1);
                var tempStorePassword = model.reg.Password;
                tempLocation.temPassword = tempStorePassword;
                _content.SaveChanges();
                var user = new ApplicationUser {
                    UserName = model.reg.Email, Email = model.reg.Email, Branch = model.reg.Branch, tillAccount = till, PhoneNumber = model.reg.PhoneNumber, homeAddress = model.reg.HouseAddress, fullName = model.reg.FullName, role = model.reg.role
                };
                //return Content(model.reg.Email);
                var result = await UserManager.CreateAsync(user, model.reg.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    //Temp Code = Teller account
                    if (model.reg.role == "Teller")
                    {
                        var roleStore   = new RoleStore <IdentityRole>(new CoreBankingApplication.Data.ApplicationDbContext());
                        var roleManager = new RoleManager <IdentityRole>(roleStore);
                        await roleManager.CreateAsync(new IdentityRole("Teller"));

                        await UserManager.AddToRoleAsync(user.Id, "Teller");
                    }


                    //Temp Code == Ends

                    if (model.reg.role == "Teller")
                    {
                        var stud = new TellerDetails
                        {
                            tillAccountNumber = till,
                            tillBalance       = 0,
                            tellerUsername    = model.reg.Email,
                            tillStatus        = true
                        };
                        _content.tellerDetails.Add(stud);
                        _content.SaveChanges();
                    }



                    if (model.reg.Email != null && model.reg.Password != null)
                    {
                        new SendEmail().SendingEmail(model.reg.Email, model.reg.Password, psd);
                    }

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    TempData["Success"] = "New User Successfully Created.";
                    return(RedirectToAction("Index", "Users"));
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #11
0
        public void AddUser()
        {
            var userClient = new UserClient();

            var userInfo = new User()
            {
                Email = "*****@*****.**", IsFacebookUser = false, AcceptedTerms = true, Name = "Alvin", Password = PasswordGenerate.Encryption("321")
            };

            userInfo.GuidKey = GuidGenerate.USER_ID;
            var apiResponse = userClient.Add(userInfo);

            Assert.IsTrue(apiResponse.IsSuccess);
        }