示例#1
0
        public ActionResult EditGrades(RegisterationViewModel model)
        {
            var model1 = GetUserViewModel();

            model1.students = model.students;
            return(View(model1));
        }
        public async Task <IActionResult> SignUp(RegisterationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new Users
                {
                    UserId      = Guid.NewGuid().ToString("n"),
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    Email       = model.Email,
                    Password    = PasswordHelper.Encrypt(model.Password),
                    PhoneNumber = model.PhoneNumber,
                    Address     = model.Address
                };
                if (user != null)
                {
                    db.Users.Add(user);
                    var getId = 0;
                    if (db.UsersRoles.Count() != 0)
                    {
                        getId = db.UsersRoles.Count();
                    }
                    else
                    {
                        getId = 0;
                    }
                    UsersRoles userRole = new UsersRoles();
                    userRole.Id     = getId + 1;
                    userRole.UserId = user.UserId;
                    userRole.RoleId = 2;
                    try
                    {
                        db.UsersRoles.Add(userRole);
                        await db.SaveChangesAsync();
                    }
                    catch (Exception e)
                    {
                        ViewBag.Message = e.InnerException.Message;
                        return(View());
                    }

                    await db.SaveChangesAsync();

                    ModelState.Clear();
                    ViewBag.Message = "Registration Successful";
                    return(View());
                }
                else
                {
                    ViewBag.Message = "Error While Registering. Please Try Again";
                    return(View());
                }
            }
            return(View(model));
        }
示例#3
0
        public async Task <IActionResult> Registeration(RegisterationViewModel model)
        {
            try
            {
                ViewBag.ErrorOccured = true;

                if (ModelState.IsValid)
                {
                    string originalCaptcha;
                    originalCaptcha = _session.CaptchaCode;
                    var registerResult = await model.RegisterUser(originalCaptcha, _db, _emailSender, ((Microsoft.AspNet.Http.HttpRequest)Request).Host.ToString());

                    if (registerResult.IsSuccessful)
                    {
                        ViewBag.ErrorOccured = false;
                    }
                    else
                    {
                        ViewBag.HtmlFormattedMessage = registerResult.FormattedMessages;
                    }


                    if (ViewBag.ErrorOccured)
                    {
                        string imgUrl;
                        _session.CaptchaCode = model.GenerateCaptchaCode(out imgUrl);
                        ViewBag.CaptchaImageAccountController = imgUrl;
                        model.CaptchaCode = "";
                        return(View(model));
                    }
                    else
                    {
                        return(RedirectToAction("RegisterationCallback", "Account"));
                    }
                }

                else
                {
                    string imgUrl;
                    _session.CaptchaCode = model.GenerateCaptchaCode(out imgUrl);
                    ViewBag.CaptchaImageAccountController = imgUrl;
                    model.CaptchaCode = "";
                    ViewBag.RoleId    = _db.Roles.FirstOrDefault(x => x.Rolename == "user").RoleId;

                    ViewBag.HtmlFormattedMessage = "لطفا تمام قسمت ها را وارد نماید";
                    return(View(model));
                }
                // return View(model);
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(HomeController.Error), "Home"));
            }
        }
示例#4
0
        public ActionResult Index()
        {
            var businessTypes = _context.BusinessTypes.ToList();
            var viewModel     = new RegisterationViewModel
            {
                Register      = new Register(),
                BusinessTypes = businessTypes
            };

            return(View("Index", viewModel));
        }
        public async Task <IActionResult> Post([FromBody] RegisterationViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var userIdentity = _mapper.Map <AppUser>(model);

            var result = await _userManager.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState)));
            }
            //var approle = new AppRole()
            //{
            //    Name = "Customer",
            //    Description = "End User",
            //    Created = DateTime.Now
            //};

            //var result2 = await _roleManager.CreateAsync(approle);

            //if (!result2.Succeeded) return new BadRequestObjectResult(Errors.AddErrorsToModelState(result2, ModelState));
            var roles = _roleManager.Roles;
            int count = 0;

            foreach (var role in roles)
            {
                var userrole = _userManager.IsInRoleAsync(userIdentity, role.Name).Result;
                if (userrole == true)
                {
                    count++;
                }
            }
            if (count == 0)
            {
                var result1 = await _userManager.AddToRoleAsync(userIdentity, "User");

                await _userManager.AddClaimAsync(userIdentity, new System.Security.Claims.Claim("role", "User"));
            }
            await _appDbContext.users.AddAsync(new User { IdentityId = userIdentity.Id, Location = "Islamabad" });

            await _appDbContext.SaveChangesAsync();

            return(new OkObjectResult("Account created"));
        }
示例#6
0
        public ActionResult Save(Register register)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new RegisterationViewModel
                {
                    Register      = register,
                    BusinessTypes = _context.BusinessTypes.ToList()
                };
                return(View("Index", viewModel));
            }

            _context.Registers.Add(register);
            _context.SaveChanges();
            return(RedirectToAction("Index", "Home"));
        }
示例#7
0
        public ActionResult Create(RegisterationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _context.Users.First(x => x.Id == model.courses1.lecturerID);
                model.courses1.LecturerName = user.FirstName + " " + user.LastName;
                _context.Courses.Add(model.courses1);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var toReturn1 = GetCourseViewModel();

            toReturn1.courses1 = model.courses1;

            return(View(toReturn1));
        }
示例#8
0
        public async Task <ActionResult> Register(RegisterationViewModel registerAccount)
        {
            if (!ModelState.IsValid)
            {
                return(View(registerAccount));
            }
            try
            {
                //Map VM to Model
                Customer customer = new Customer();
                customer.UserName     = registerAccount.UserName;
                customer.PasswordHash = registerAccount.Password;
                customer.Email        = registerAccount.Email;
                customer.Address      = registerAccount.Address;


                IdentityResult result
                    = await manager.CreateAsync(customer, registerAccount.Password);

                if (result.Succeeded)
                {
                    manager.AddToRole(customer.Id, "customer");
                    //MAnager SignIn
                    IAuthenticationManager authenticationManager =
                        HttpContext.GetOwinContext().Authentication;
                    SignInManager <Customer, string> signinmanager =
                        new SignInManager <Customer, string>
                            (manager, authenticationManager);
                    signinmanager.SignIn(customer, true, true);

                    return(RedirectToAction("index", "Product"));
                }
                else
                {
                    //foreach ModelState.AddModelError("", (result.Errors.ToList())[0]);

                    return(View(registerAccount));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(registerAccount));
            }
        }
        public ActionResult CustomerRegister(RegisterationViewModel Reg, string command) //command recive with form button
        {
            ModelState["Customer.VerifyCode"].Errors.Clear();


            //sing up for customer Role and Register For Admin And Rgistered for Driver
            if (command == "Sing Up")
            {
                if (ModelState.IsValid)
                {
                    RegisterationCrudViewModel cust_reg = new RegisterationCrudViewModel();



                    string userexist = cust_reg.register(Reg.Customer); // chek valid user


                    if (userexist == "0") //if user is already register
                    {
                        TempData["Erroruserexist"] = "User is already exist ,Plz login";
                        return(RedirectToAction("Login", "Registeration", new { id = 2 }));
                    }
                    else
                    {
                        //Picture Save after user verification
                        Reg.Customer.UserImageUrl = PictureSave(Reg.Customer.UserImage);
                        TempData["UserData"]      = Reg;
                        //picture method called it define in botton
                        if (TempData["extensionerror"] == null) //checked extension
                        {
                            TempData["RegistrationRole"] = command;
                            TempData.Keep();
                            codesendmail();                   //mail send method called
                            return(RedirectToAction("VerfyCode", "Registeration"));
                        }
                        else
                        {
                            return(RedirectToAction("CustomerRegister", "Registeration")); //redirect customer page with error message
                        }
                    }
                }
            }
            return(View());
        }
示例#10
0
        //here after verify customer save in database also forgin key store
        public string Customer_register(RegisterationViewModel verifiedUser)
        {
            //encrypted password
            string enc = verifiedUser.Customer.UserPassword;

            byte[] encode = new byte[enc.Length];
            encode = Encoding.UTF8.GetBytes(verifiedUser.Customer.UserPassword);
            string enc_password = Convert.ToBase64String(encode);

            string message    = "";
            string connection = ConfigurationManager.ConnectionStrings["E_MART"].ConnectionString;

            using (SqlConnection con = new SqlConnection(connection))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("User_Registration", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@UserFirstName", verifiedUser.Customer.FirstName);
                    cmd.Parameters.AddWithValue("@UserLastName", verifiedUser.Customer.LastName);
                    cmd.Parameters.AddWithValue("@UserEmail", verifiedUser.Customer.UserEmail);
                    cmd.Parameters.AddWithValue("@UserPassword", enc_password);
                    cmd.Parameters.AddWithValue("@IsActive", 1);
                    cmd.Parameters.AddWithValue("@UserRoleId", 2);
                    cmd.Parameters.AddWithValue("@UserImageUrl", verifiedUser.Customer.UserAddress);
                    cmd.Parameters.AddWithValue("@UserPhoneNumber", verifiedUser.Customer.PhoneNumber);
                    cmd.Parameters.AddWithValue("@UserAddress", verifiedUser.Customer.UserImageUrl);
                    cmd.Parameters.AddWithValue("@UserLat", verifiedUser.Customer.UserLat);
                    cmd.Parameters.AddWithValue("@UserLon", verifiedUser.Customer.UserLon);
                    if (cmd.ExecuteNonQuery() > 0)
                    {
                        message = "User sucessfully add";
                    }
                    else
                    {
                        throw new Exception("Problem During Registeration");
                    }
                    con.Close();
                }
                return(message);
            }
        }
示例#11
0
        public ActionResult AddStudentToCourse(RegisterationViewModel model)
        {
            try
            {
                if (!(_context.Users.Where(x => x.Role.Equals("Student")).Any(x => x.Id.Equals(model.Grade.Studentid))))
                {
                    TempData["notFOUND"] = "This USER Doesn't Exist";
                }
                if (!(_context.Courses.Any(x => x.Courseid.Equals(model.Grade.Courseid))))
                {
                    TempData["coursenotFOUND"] = "This course not Exist";
                }
                if (_context.Grades.Any(x => x.Studentid.Equals(model.Grade.Studentid)))
                {
                    TempData["userMSG"] = "The student already Registerd to Course";
                }
                //if(_context.Courses.Any(x=>x.Day.Equals(model.courses1.Day) && x.TimeStart.Equals(model.courses1.TimeStart)))
                //{
                //    TempData["sametime"] = "This Student has course at the same time";
                //}
                if (TempData["notFound"] != null || TempData["userMSG"] != null || TempData["notFOUND1"] != null)
                {
                    var toReturn1 = GetRegisterationViewModel();
                    toReturn1.Grade = model.Grade;
                    return(View(toReturn1));
                }
                else
                {
                    _context.Grades.Add(model.Grade);
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
            }
            var toReturn = GetRegisterationViewModel();

            toReturn.Grade = model.Grade;
            return(View(toReturn));
        }
        public ActionResult ShopManagerRegister(RegisterationViewModel Reg, string command)
        {
            if (command == "Registers")
            {
                //ModelState["PinCode"].Errors.Clear();
                //ModelState["VehicleNumber"].Errors.Clear();
                if (ModelState.IsValid)
                {
                    RegisterationCrudViewModel ShopManager = new RegisterationCrudViewModel();



                    string userexist = ShopManager.register(Reg.ShopManager);


                    if (userexist == "0")
                    {
                        TempData["Erroruserexist"] = "User is already exist ,Plz login";
                        return(RedirectToAction("ShopManagerRegister", "Registeration"));
                    }
                    else
                    {
                        Reg.ShopManager.UserImageUrl = PictureSave(Reg.ShopManager.UserImage);
                        TempData["UserData"]         = Reg;
                        if (TempData["extensionerror"] == null)
                        {
                            TempData["RegistrationRole"] = command;
                            TempData.Keep();
                            codesendmail();
                            return(RedirectToAction("VerfyCode", "Registeration"));
                        }

                        else
                        {
                            return(RedirectToAction("ShopManagerRegister", "Registration"));
                        }
                    }
                }
            }
            return(View());
        }
示例#13
0
        /*
         * public RegisterationViewModel EditUser(int id)
         * {
         *
         *             User user=new User();
         * string connection = ConfigurationManager.ConnectionStrings["E_MART"].ConnectionString;
         *
         * using (SqlConnection con = new SqlConnection(connection))
         * {
         * con.Open();
         * using (SqlCommand cm = new SqlCommand("sp_User_EditUser", con))
         * {
         * cm.CommandType = System.Data.CommandType.StoredProcedure;
         * cm.Parameters.AddWithValue("@UserId", id);
         *
         * SqlDataReader dr = cm.ExecuteReader();
         * if (dr.Read())
         * {
         *  user.UserFirstName = dr["User_FirstName"].ToString();
         *  user.UserLastName = dr["User_LastName"].ToString();
         *  user.UserAddress = dr["User_Address"].ToString();
         *  user.User_Password = dr["User_Password"].ToString();
         *  user.ConfirmPassowrd = dr["User_Password"].ToString();
         *  user.Image = dr["User_Image"].ToString();
         *  user.UserId =int.Parse(dr["UserId"].ToString());
         *
         * }
         *
         * //decrypted password
         * string dec = user.User_Password;
         * byte[] encodedDataAsBytes = System.Convert.FromBase64String(dec);
         * string dec_pass = System.Text.Encoding.UTF8.GetString(encodedDataAsBytes);
         * //else
         * //{
         * //}
         * user.User_Password = dec_pass;
         * user.ConfirmPassowrd = dec_pass;
         * }
         * }
         * return user;
         *
         *
         * }
         * */
        public string UpdateUser(RegisterationViewModel user)
        {
            //encrypted password
            string enc = user.User.UserPassword;

            byte[] encode = new byte[enc.Length];
            encode = Encoding.UTF8.GetBytes(user.User.UserPassword);
            string enc_password = Convert.ToBase64String(encode);
            string message      = "";
            string connection   = ConfigurationManager.ConnectionStrings["E_MART"].ConnectionString;

            using (SqlConnection con = new SqlConnection(connection))
            {
                con.Open();
                using (SqlCommand cm = new SqlCommand("sp_User_UpdateUser", con))
                {
                    cm.CommandType = System.Data.CommandType.StoredProcedure;
                    cm.Parameters.AddWithValue("@User_FirstName", user.User.FirstName);
                    cm.Parameters.AddWithValue("@User_LastName", user.User.LastName);
                    cm.Parameters.AddWithValue("@User_Address", user.User.UserAddress);
                    cm.Parameters.AddWithValue("@UserId", user.User.UserId);
                    cm.Parameters.AddWithValue("@User_Password", enc_password);
                    cm.Parameters.AddWithValue("@User_Image", user.User.UserImageUrl);
                    int check = cm.ExecuteNonQuery();
                    if (check > 0)
                    {
                        message = "1";
                    }
                    else if (check == 1)
                    {
                        message = "0";
                    }
                    else
                    {
                        throw new Exception("Database Problem");
                    }
                }
            }
            return(message);
        }
        //send mail method are call in customer,driver,admin
        public ActionResult codesendmail()
        {
            string numbers   = "0123456789";
            Random objrandom = new Random();
            string strrandom = string.Empty;

            for (int i = 0; i < 5; i++)
            {
                int temp = objrandom.Next(0, numbers.Length);
                strrandom += temp;
            }
            ViewBag.otp = strrandom;

            TempData["code"] = strrandom;

            TempData.Keep();

            RegisterationViewModel verifiedUser = TempData["Userdata"] as RegisterationViewModel;

            //string ahsan = verifiedUser.UserFirstName;
            if (verifiedUser.Admin != null)
            {
                WebMail.Send(verifiedUser.Admin.UserEmail, "Well Come '" + verifiedUser.Admin.UserEmail + "_" + verifiedUser.Admin.UserEmail + "' Emart", "Dear Sir,<br/> You are Register this mobile NO  :" + verifiedUser.Admin.PhoneNumber + "<br/><br/> Your are Register With Email  :" + verifiedUser.Admin.UserEmail + "<br/><br/>Your Verfy Code Is :" + strrandom
                             , null, null, null, true, null, null, null, null, null, null);
            }
            else if (verifiedUser.ShopManager != null)
            {
                WebMail.Send(verifiedUser.ShopManager.UserEmail, "Well Come '" + verifiedUser.ShopManager.UserEmail + "_" + verifiedUser.ShopManager.UserEmail + "' Emart", "Dear Sir,<br/> You are Register this mobile NO  :" + verifiedUser.ShopManager.PhoneNumber + "<br/><br/> Your are Register With Email  :" + verifiedUser.ShopManager.UserEmail + "<br/><br/>Your Verfy Code Is :" + strrandom
                             , null, null, null, true, null, null, null, null, null, null);
            }
            else if (verifiedUser.Customer != null)
            {
                WebMail.Send(verifiedUser.Customer.UserEmail, "Well Come '" + verifiedUser.Customer.UserEmail + "_" + verifiedUser.Customer.UserEmail + "' Emart", "Dear Sir,<br/> You are Register this mobile NO  :" + verifiedUser.Customer.PhoneNumber + "<br/><br/> Your are Register With Email  :" + verifiedUser.Customer.UserEmail + "<br/><br/>Your Verfy Code Is :" + strrandom
                             , null, null, null, true, null, null, null, null, null, null);
            }

            TempData.Keep();
            return(RedirectToAction("VerfyCode", "Registeration"));
        }
示例#15
0
        public async Task <IActionResult> Register(RegisterationViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email    = model.Email,
                    Board    = new Board
                    {
                        Name        = "Test Board",
                        Description = "A brief explanation of what this board has in it.",
                        Bulletin    = new Bulletin
                        {
                            Name        = "A Bulletin",
                            Description = "Bulletin description."
                        }
                    }
                };

                IdentityResult result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _signinManager.SignInAsync(user, false);

                    return(RedirectToAction("Index", "Home"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            return(View());
        }
示例#16
0
 public ActionResult Edit(RegisterationViewModel model)
 {
     try
     {
         var user = _context.Courses.First(x => x.Courseid == model.courses1.Courseid);
         user.DateMoedA  = model.courses1.DateMoedA;
         user.DateMoedB  = model.courses1.DateMoedB;
         user.Day        = model.courses1.Day;
         user.lecturerID = model.courses1.lecturerID;
         //user.LecturerName = _context.Users.Where(x => x.Id.Equals(model.courses1.lecturerID)).Select(x => x.FirstName).ToString();
         user.NameCourse = model.courses1.NameCourse;
         user.TimeEnd    = model.courses1.TimeEnd;
         user.TimeStart  = model.courses1.TimeStart;
         //user.RoleID = model.user1.RoleID;
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         var model1 = GetCourseViewModel();
         model1.user12 = model.user12;
         return(View(model1));
     }
 }
        public async Task <ActionResult> Register(RegisterationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var JobSeekerObj = model.JobSeeker;
                var user         = new ApplicationUser
                {
                    UserName    = JobSeekerObj.Email,
                    Email       = JobSeekerObj.Email,
                    FirstName   = JobSeekerObj.FirstName,
                    Lastname    = JobSeekerObj.LastName,
                    PhoneNumber = JobSeekerObj.PhoneNumber
                };
                var result = await UserManager.CreateAsync(user, JobSeekerObj.Password);

                if (result.Succeeded)
                {
                    if (model.RegistrationType == 0)
                    {
                        UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, JobSeekerObj.FirstName));
                        UserManager.AddToRole(user.Id, "JobSeeker");
                    }
                    else
                    {
                        UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, JobSeekerObj.FirstName));
                        UserManager.AddToRole(user.Id, "Employer");
                    }
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // 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);

                    string EmailMessage = "";
                    using (var context = new ApplicationDbContext())
                    {
                        EmailMessage = context.Configurations.Where(c => c.ConfigurationKey == "RegistrationConfirmationEmail")
                                       .ToList()
                                       .First()
                                       .ConfigurationValue;
                    }

                    EmailMessage = EmailMessage.Replace("{0}", user.UserName);
                    EmailMessage = EmailMessage.Replace("{1}", callbackUrl);

                    await
                    UserManager.SendEmailAsync(user.Id, "Confirm your account", EmailMessage);

                    return(RedirectToAction("RegisterConfirmation", "Account"));
                }
                AddErrors(result);
                //if (model.RegistrationType == 0)
                //{
                //    var JobSeekerObj = model.JobSeeker;
                //    var user = new ApplicationUser
                //    {
                //        UserName = JobSeekerObj.Email,
                //        Email = JobSeekerObj.Email,
                //        FirstName = JobSeekerObj.FirstName,
                //        Lastname = JobSeekerObj.LastName,
                //        PhoneNumber = JobSeekerObj.PhoneNumber
                //    };
                //    var result = await UserManager.CreateAsync(user, JobSeekerObj.Password);
                //    if (result.Succeeded)
                //    {
                //        UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, JobSeekerObj.FirstName));

                //        UserManager.AddToRole(user.Id, "JobSeeker");
                //        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                //        // 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",
                //                string.Format("Please confirm your account by clicking <a href=\"{0}\">here</a>",
                //                    callbackUrl));

                //        return RedirectToAction("RegisterConfirmation", "Account");
                //    }
                //    AddErrors(result);
                //}
                //else
                //{
                //    var EmployerObj = model.Employer;
                //    var user = new ApplicationUser { UserName = EmployerObj.Email, Email = EmployerObj.Email, FirstName = EmployerObj.Name, Lastname = "Employer", PhoneNumber = EmployerObj.PhoneNumber };
                //    var result = await UserManager.CreateAsync(user, EmployerObj.Password);
                //    if (result.Succeeded)
                //    {
                //        UserManager.AddClaim(user.Id, new Claim(ClaimTypes.GivenName, EmployerObj.Name));

                //        UserManager.AddToRole(user.Id, "Employer");

                //        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                //        // 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 career visa account", string.Format("Thank you for signing up to career visa portal! <br/>Please confirm your account by clicking <a href=\"{0}\">here</a> <br/>Love,<br/>Career Visa team", callbackUrl));

                //        return RedirectToAction("RegisterConfirmation", "Account");
                //    }
                //    AddErrors(result);
                //}
            }

            // If we got this far, something failed, redisplay form
            return(View("Register", model));
        }
        public ActionResult FinalyCustomerRegister(RegisterationViewModel REG, string command1)
        {
            //firstly we check a code is npot equall
            string role = (TempData["RegistrationRole"].ToString());
            string C;

            if (TempData["code"] != null)          //code recive in send mail method
            {
                C = (TempData["code"].ToString()); //code assign in varible c for if check


                if (REG.User.VerifyCode == C)                                                                 //code match ,user enter
                {
                    RegisterationViewModel     verifiedUser = TempData["Userdata"] as RegisterationViewModel; //tempdata user(user reg form) assign in veifieduser
                    RegisterationCrudViewModel cust_reg     = new RegisterationCrudViewModel();
                    if (role == "Sing Up")                                                                    //its for customer sing up
                    {
                        cust_reg.Customer_register(verifiedUser);

                        //PictureSave(REG);
                        return(RedirectToAction("Login", "Registeration", new { id = Session["LoginId"] })); //user sucessfullly registered and goes customer home page
                    }

                    else if (role == "Register")// its for admin
                    {
                        cust_reg.Admin_Register(verifiedUser);
                        // PictureSave(REG);
                        List <RegisterationViewModel> Reg = new List <RegisterationViewModel>();
                        //Reg.Add(verifiedUser);
                        Session["UserData"] = Reg;

                        return(RedirectToAction("Login", "Registeration", new { id = Session["LoginId"] })); //user sucessfullly registered and goes  admin home page
                    }
                    else if (role == "Registers")
                    {
                        cust_reg.ShopkeeperRegister(verifiedUser);
                        // PictureSave(REG);
                        List <RegisterationViewModel> Reg = new List <RegisterationViewModel>();
                        //Reg.Add(verifiedUser);
                        Session["UserData"] = Reg;

                        return(RedirectToAction("Login", "Registeration", new { id = Session["LoginId"] })); //user sucessfullly registered and goes  admin home page
                    }
                    else if (role == "Reset Password")
                    {
                        return(RedirectToAction("UpdatePassword", "Registeration", new { id = Session["LoginId"] })); //user sucessfullly registered and goes update  home page
                    }
                }
                else
                {
                    TempData["WrongCode"] = "Yor code is not verified <br/> Plz TRY Again"; //code is not verified
                }
            }
            else
            {
                TempData["Errormessage"] = "Enter your 5 digit code"; //code is not entered,
            }
            if (command1 == "Resend Code")                            //here is code is resend code and redirect to verify code page
            {
                string numbers   = "0123456789";
                Random objrandom = new Random();
                string strrandom = string.Empty;
                for (int i = 0; i < 5; i++)
                {
                    int temp = objrandom.Next(0, numbers.Length);
                    strrandom += temp;
                }
                ViewBag.otp = strrandom;

                TempData["code"] = strrandom;
                TempData.Keep();

                RegisterationViewModel verifiedUser = TempData["Userdata"] as RegisterationViewModel;
                //string ahsan = verifiedUser.UserFirstName;
                if (verifiedUser.Admin != null)
                {
                    WebMail.Send(verifiedUser.Admin.UserEmail, "Well Come '" + verifiedUser.Admin.UserEmail + "_" + verifiedUser.Admin.UserEmail + "' Emart", "Dear Sir,<br/> You are Register this mobile NO  :" + verifiedUser.Admin.PhoneNumber + "<br/><br/> Your are Register With Email  :" + verifiedUser.Admin.UserEmail + "<br/><br/>Your Verfy Code Is :" + strrandom
                                 , null, null, null, true, null, null, null, null, null, null);
                }
                else if (verifiedUser.ShopManager != null)
                {
                    WebMail.Send(verifiedUser.ShopManager.UserEmail, "Well Come '" + verifiedUser.ShopManager.UserEmail + "_" + verifiedUser.ShopManager.UserEmail + "' Emart", "Dear Sir,<br/> You are Register this mobile NO  :" + verifiedUser.ShopManager.PhoneNumber + "<br/><br/> Your are Register With Email  :" + verifiedUser.ShopManager.UserEmail + "<br/><br/>Your Verfy Code Is :" + strrandom
                                 , null, null, null, true, null, null, null, null, null, null);
                }
                else if (verifiedUser.Customer != null)
                {
                    WebMail.Send(verifiedUser.Customer.UserEmail, "Well Come '" + verifiedUser.Customer.UserEmail + "_" + verifiedUser.Customer.UserEmail + "' Emart", "Dear Sir,<br/> You are Register this mobile NO  :" + verifiedUser.Customer.PhoneNumber + "<br/><br/> Your are Register With Email  :" + verifiedUser.Customer.UserEmail + "<br/><br/>Your Verfy Code Is :" + strrandom
                                 , null, null, null, true, null, null, null, null, null, null);
                }



                TempData.Keep();
                TempData["ResendMessage"] = "Check Your Email You get 5 digit Verify Code"; //code is not entered,
                return(RedirectToAction("VerfyCode", "Registeration", new { id = Session["LoginId"] }));
            }
            return(RedirectToAction("VerfyCode", "Registeration"));
        }
示例#19
0
        //here after verify user save in database also forgin key store
        public int Admin_Register(RegisterationViewModel verifiedUser)
        {
            //encrypted password
            string enc = verifiedUser.Admin.UserPassword;

            byte[] encode = new byte[enc.Length];
            encode = Encoding.UTF8.GetBytes(verifiedUser.Admin.UserPassword);
            string enc_password = Convert.ToBase64String(encode);


            int    user_id    = 0;
            string connection = ConfigurationManager.ConnectionStrings["E_MART"].ConnectionString;

            using (SqlConnection con = new SqlConnection(connection))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand("Admin_Registration", con))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@UserFirstName", verifiedUser.Admin.FirstName);
                    cmd.Parameters.AddWithValue("@UserLastName", verifiedUser.Admin.LastName);
                    cmd.Parameters.AddWithValue("@UserEmail", verifiedUser.Admin.UserEmail);
                    cmd.Parameters.AddWithValue("@UserPassword", enc_password);
                    cmd.Parameters.AddWithValue("@IsActive", 1);
                    cmd.Parameters.AddWithValue("@UserRoleId", 1);
                    cmd.Parameters.AddWithValue("@UserImageUrl", verifiedUser.Admin.UserAddress);
                    cmd.Parameters.AddWithValue("@UserPhoneNumber", verifiedUser.Admin.PhoneNumber);
                    cmd.Parameters.AddWithValue("@UserAddress", verifiedUser.Admin.UserImageUrl);
                    cmd.Parameters.AddWithValue("@UserLat", verifiedUser.Admin.UserLat);
                    cmd.Parameters.AddWithValue("@UserLon", verifiedUser.Admin.UserLon);


                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    DataTable      dt  = new DataTable();
                    sda.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        user_id = int.Parse(dt.Rows[0]["UserId"].ToString());
                    }

                    /*
                     * SqlDataReader dr = cmd.ExecuteReader();
                     * if(dr.HasRows)
                     * {
                     * if (dr.Read())
                     * {
                     *   verifiedUser.User.UserId = int.Parse(dr["UserId"].ToString());
                     * }
                     * }
                     *
                     *
                     *
                     * //company detail
                     * con.Close();
                     * con.Open();
                     * using (SqlCommand cm = new SqlCommand("Company_info", con))
                     * {
                     * cm.CommandType = System.Data.CommandType.StoredProcedure;
                     *
                     * cm.Parameters.AddWithValue("@CompanyRegNum", verifiedUser.Comp_Reg_No);
                     * cm.Parameters.AddWithValue("@CompanyOwner", verifiedUser.Comp__owner_name);
                     * //cm.Parameters.AddWithValue("@owner_cnic", verifiedUser.owner_cnic);
                     * //cm.Parameters.AddWithValue("@owner_ph", verifiedUser.owner_ph);
                     * cm.Parameters.AddWithValue("@CompanyVehicleQuanitity", verifiedUser.comp_no_vehicle);
                     * cm.Parameters.AddWithValue("@CompanyWorth", verifiedUser.comp_worth);
                     * cm.Parameters.AddWithValue("@CompanyAddress", verifiedUser.comp_adress);
                     * cm.Parameters.AddWithValue("@CompanyPhoneNumber", verifiedUser.CompanyPhoneNumber);
                     * cm.Parameters.AddWithValue("@CompanyUserId", verifiedUser.UserId);
                     * cm.ExecuteNonQuery();
                     * con.Close();
                     * */
                }
            }
            return(user_id);
        }
示例#20
0
 public async Task <Result <bool> > Registration([FromBody] RegisterationViewModel newUser)
 {
     return(await _manager.AddUser(newUser));
 }
示例#21
0
        public async Task <Result <bool> > AddUser(RegisterationViewModel userViewModel)
        {
            try
            {
                var user = new UserEntity {
                    Name        = userViewModel.Name,
                    Email       = userViewModel.Email,
                    PhoneNumber = userViewModel.PhoneNumber,
                    Address     = userViewModel.Address,
                    Type        = userViewModel.Type,
                    Picture     = userViewModel.Picture,
                    Gender      = userViewModel.Gender,
                };

                // Check for Type
                if (!Enum.IsDefined(typeof(EUserType), userViewModel.Type))
                {
                    throw new Exception(EResultMessage.NotUserType.ToString());
                }

                // Add user Typr
                user.Type = userViewModel.Type;

                if (userViewModel.Password != userViewModel.RepeatPassword)
                {
                    throw new Exception(EResultMessage.PasswordNotMatched.ToString());
                }

                // Hash user password
                user.HashPassword = Protected.CreatePasswordHash(userViewModel.Password);

                // Add user
                var result = Add(user);

                if (result == null)
                {
                    throw new Exception(EResultMessage.DatabaseError.ToString());
                }

                SaveChanges();

                var token = _tokenManager.GenerateUserToken(result).Token;

                var confirmLink = string.Format("{0}/api/user/confirm-account", _requestAttributes.AppBaseUrl);

                string body = File.ReadAllText("wwwroot/html/registartion.html");
                body = body.Replace("{link-path}", confirmLink);
                body = body.Replace("{user-name}", user.Name);
                body = body.Replace("{user-id}", user.Id.ToString());
                body = body.Replace("{user-token}", token);


                await _mailProvider.SendAsync(new MailMessageViewModel
                {
                    From       = MailProvider.SMTP_USER,
                    To         = user.Email,
                    IsBodyHtml = true,
                    Body       = body,
                    Subject    = "Confirm your account on Got It"
                });

                return(ResultHelper.Succeeded(true, message: EResultMessage.RegistrationDone.ToString()));
            }
            catch (DuplicateDataException)
            {
                return(ResultHelper.Failed(data: false, message: EResultMessage.EmailExists.ToString()));
            }
            catch (Exception e)
            {
                return(ResultHelper.Failed <bool>(message: e.Message));
            }
        }