Ejemplo n.º 1
0
        public JsonResult VerifiyUser(UsermasterView usermaster)
        {
            try
            {
                var givenEmail     = usermaster.EmailId;
                var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster);
                var isUser         = _iUserMaster.CheckUsernameExists(usermaster.UserName);
                if (isUser)
                {
                    var user = _iUserMaster.GetUserByUsername(usermaster.UserName);
                    if (user.EmailId == givenEmail)
                    {
                        MailMessage mail = new MailMessage("*****@*****.**", givenEmail);
                        mail.Subject    = "Subject";
                        mail.IsBodyHtml = true;
                        mail.Body       = "this is email body";

                        SmtpClient client = new SmtpClient("64.233.166.109");
                        client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = false;
                        client.Credentials           = new NetworkCredential("*****@*****.**", "lilla34402");
                        client.Port      = 587;
                        client.EnableSsl = true;


                        //Add this line to bypass the certificate validation
                        // But do not add these lines in a production code
                        System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object s,
                                                                                                      System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                                                                                      System.Security.Cryptography.X509Certificates.X509Chain chain,
                                                                                                      System.Net.Security.SslPolicyErrors sslPolicyErrors)
                        {
                            return(true);
                        };


                        client.Send(mail);
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Email");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid UserName");
                }


                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        public ActionResult Register(UsermasterView usermaster)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster);
                    var isUser         = _iUserMaster.CheckUsernameExists(usermaster.UserName);
                    if (isUser)
                    {
                        ModelState.AddModelError("", "Username already exists");
                    }

                    AesAlgorithm aesAlgorithm = new AesAlgorithm();

                    var userId = _iUserMaster.AddUser(autoUsermaster);
                    if (userId != -1)
                    {
                        PasswordMaster passwordMaster = new PasswordMaster
                        {
                            CreateDate = DateTime.Now,
                            UserId     = userId,
                            PasswordId = 0,
                            Password   = aesAlgorithm.EncryptString(usermaster.Password)
                        };

                        var passwordId = _iPassword.SavePassword(passwordMaster);

                        if (passwordId != -1)
                        {
                            TempData["MessageRegistration"] = "Registration Successful";
                        }
                    }

                    return(RedirectToAction("Register", "Registration"));
                }
                else
                {
                    return(View("Register", usermaster));
                }
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Register(UsermasterView usermaster)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!this.IsCaptchaValid("Captcha is not valid"))
                    {
                        ModelState.AddModelError("", "Error: captcha is not valid.");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckUsernameExists(usermaster.UserName))
                    {
                        ModelState.AddModelError("", "UserName already exists");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckEmailIdExists(usermaster.EmailId))
                    {
                        ModelState.AddModelError("", "EmailId already exists");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckMobileNoExists(usermaster.MobileNo))
                    {
                        TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists";
                    }

                    var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster);
                    var salt           = GenerateRandomNumbers.RandomNumbers(20);
                    var saltedpassword = GenerateHashSha512.Sha512(usermaster.Password, salt);

                    var userId = _iUserMaster.AddUser(autoUsermaster, saltedpassword, salt, Convert.ToInt16(StatusMain.Roles.User));
                    if (userId != -1)
                    {
                        var emailVerficationToken = GenerateHashSha256.ComputeSha256Hash((GenerateRandomNumbers.RandomNumbers(6)));
                        _verification.SendRegistrationVerificationToken(userId, emailVerficationToken);

                        SendingEmailhelper sendingEmailhelper = new SendingEmailhelper();
                        var name = string.Concat(usermaster.FirstName, usermaster.LastName);
                        await sendingEmailhelper.SendVerificationEmailasync(usermaster.EmailId, name, emailVerficationToken, "Registration", Convert.ToString(userId));

                        TempData["MessageRegistration"] = "Thank you. Your Registration has been completed successfully.";
                    }
                    else
                    {
                        TempData["ErrorRegistration"] = "Something Went Wrong While you are registering.Please try after sometime.";
                    }

                    return(RedirectToAction("Register", "Registration"));
                }
                else
                {
                    return(View("Register", usermaster));
                }
            }
            catch
            {
                throw;
            }
        }