Exemplo n.º 1
0
        public IActionResult Register(RegViewModel model)
        {
            if (HttpContext.Session.GetInt32("UserId") != null)
            {
                return(RedirectToAction("Home", "Ideas"));
            }

            if (ModelState.IsValid)
            {
                User ExistingUser = _context.Users.SingleOrDefault(u => u.Email == model.Email);
                if (ExistingUser != null)
                {
                    ViewBag.Message = "Email is already in use.";
                    return(View("Index", model));
                }
                User NewUser = new User
                {
                    Name     = model.Name,
                    Alias    = model.Alias,
                    Email    = model.Email,
                    Password = model.Password
                };
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                NewUser.Password = Hasher.HashPassword(NewUser, model.Password);
                _context.Add(NewUser);
                _context.SaveChanges();
                int UserId = _context.Users.Last().UserId;
                HttpContext.Session.SetInt32("UserId", UserId);
                return(RedirectToAction("Home", "Ideas"));
            }

            return(View("Index", model));
        }
Exemplo n.º 2
0
        public IActionResult Register(RegViewModel model)
        {
            PasswordHasher <RegViewModel> hasher = new PasswordHasher <RegViewModel>();

            //check if user email is already in database and add error if so
            if (_context.users.Where(user => user.username == model.Email).SingleOrDefault() != null)
            {
                ModelState.AddModelError("Email", "Username already in use, please log in or choose another username");
            }
            //if form is valid add new user to database and hash password
            if (ModelState.IsValid)
            {
                User NewUser = new User
                {
                    name       = model.Name,
                    alias      = model.Alias,
                    username   = model.Email,
                    password   = hasher.HashPassword(model, model.Password),
                    created_at = DateTime.Now,
                    updated_at = DateTime.Now,
                };
                //save new user object to add to session
                User fresh = _context.users.Add(NewUser).Entity;
                _context.SaveChanges();
                HttpContext.Session.SetInt32("id", fresh.userid);
                HttpContext.Session.SetString("alias", fresh.alias);
                return(RedirectToAction("Home", "Trash"));
            }
            return(View("Entry"));
        }
        public ActionResult Registration(RegProducerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBagProducerList();
                return(View("Index", model));
            }

            ViewBagAppointmentList(model.ProducerId);
            var producerName = DB.producernames.Single(x => x.ProducerId == model.ProducerId).ProducerName;
            var company      = DB.AccountCompany.SingleOrDefault(x => x.ProducerId == model.ProducerId);

            // если от данного производителя регистрировались, возвращаем форму для регистрации пользователя с моделью RegDomainViewModel
            if (company != null)
            {
                var modelDomainView = new RegDomainViewModel()
                {
                    Producers = model.ProducerId, ProducerName = producerName
                };
                ViewBag.DomainList = company.CompanyDomainName
                                     .Select(x => new OptionElement {
                    Text = '@' + x.Name, Value = x.Id.ToString()
                })
                                     .ToList();
                return(View("DomainRegistration", modelDomainView));
            }

            var modelUi = new RegViewModel()
            {
                ProducerId = model.ProducerId, ProducerName = producerName
            };

            return(View(modelUi));
        }
Exemplo n.º 4
0
        public ActionResult RegAuto(RegViewModel model)
        {
            if (ModelState.IsValid)
            {
                #region 注册用户并登录
                try
                {
                    Member mb = MemberService.Create(model);

                    MemberService.SetLoginCookie(mb);

                    return(Redirect(Url.Action("regok")));
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog("用户:" + model.Email + "注册失败!", ex);
                    TempData["FormError"] = true;
                    return(View(model));
                }
                #endregion
            }
            else
            {
                TempData["FormError"] = true;
                return(View(model));
            }
        }
Exemplo n.º 5
0
        public async Task <Tuple <bool, string> > Reg(RegViewModel rvm)
        {
            var au = new Users
            {
                UserName     = rvm.UserName,
                UserPassword = rvm.UserPassword,
                Password     = Security.Sha256(rvm.UserPassword),
                LoginIP      = Utils.GetIP(),
                UserLoginNum = 0,
                Valid        = false,
                lastdate     = DateTime.Now,
                ActiveCode   = Guid.NewGuid().ToString("N")
            };

            Insert(au);
            await UserDetailManage.InsertAsync(new UserDetail
            {
                DisplayName = rvm.DisplayName,
                CompanyName = rvm.CompanyName,
                Email       = rvm.Email,
                Address     = rvm.Address,
                Tel         = rvm.Tel,
                UserID      = au.UserID,
            });

            await UserRoleManage.InsertAsync(new UserRole
            {
                UserID = au.UserID,
                RoleID = 4
            });

            return(await SendRegisterMail(au.UserName, au.UserID.ToString(), au.ActiveCode, rvm.Email));
        }
Exemplo n.º 6
0
 public ActionResult Registration(RegViewModel reg)
 {
     if (ModelState.IsValid)
     {
         Models.User user = new Models.User();
         user.First_Name  = reg.First_Name;
         user.Last_Name   = reg.Last_Name;
         user.Email       = reg.Email;
         user.Password    = reg.Password;
         user.Reg_Date    = DateTime.Now;
         user.Last_Date   = DateTime.Now;
         user.Delete_Date = DateTime.MaxValue;
         user.Status      = 0;
         admin.CreateUser(user, 2);
         LoginViewModel login = new LoginViewModel()
         {
             email    = reg.Email,
             password = reg.Password
         };
         Login(login);
     }
     else
     {
         return(View(reg));
     }
     return(Redirect("~/Home/Index"));
 }
Exemplo n.º 7
0
        public IActionResult Register(RegViewModel adduser)
        {
            if (ModelState.IsValid)
            {
                User UserInDB = _context.Users.SingleOrDefault(user => user.Email == adduser.Email);
                if (UserInDB != null)
                {
                    ViewBag.Message = "This email already exists in the database.";
                    return(View("Register", adduser));
                }
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                User AddUserinDB             = new User
                {
                    FirstName = adduser.FirstName,
                    LastName  = adduser.LastName,
                    Email     = adduser.Email,
                    Password  = adduser.Password,
                };
                AddUserinDB.Password = Hasher.HashPassword(AddUserinDB, AddUserinDB.Password);
                _context.Add(AddUserinDB);
                _context.SaveChanges();
                AddUserinDB = _context.Users.SingleOrDefault(user => user.Email == AddUserinDB.Email);

                var activeuser = _context.Users.SingleOrDefault(user => user.Email == adduser.Email);
                HttpContext.Session.SetString("Loggedinuser", activeuser.FirstName + " " + activeuser.LastName);
                HttpContext.Session.SetInt32("UserId", AddUserinDB.UserId);
                return(RedirectToAction("Dashboard"));
            }
            else
            {
                return(View("Register", adduser));
            }
        }
Exemplo n.º 8
0
        public RegPage(int RegType)
        {
            InitializeComponent();

#if !DEBUG
            this.WindowState = System.Windows.WindowState.Maximized;
            this.Topmost     = true;

            // 防止超出第一屏幕在第二屏幕边缘也显示
            this.ResizeMode = System.Windows.ResizeMode.NoResize;
#endif


            RegViewModel viewModel = new RegViewModel(this, RegType);

            viewModel.Init();
            this.DataContext = viewModel;



            //鼠标不需要显示
            if (!Res.Resources.GetRes().DisplayCursor)
            {
                Mouse.OverrideCursor = Cursors.None;
            }



            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged);
        }
Exemplo n.º 9
0
        public string reg(RegViewModel rvm)
        {
            var au = new Users
            {
                UserName     = rvm.UserName,
                UserPassword = rvm.UserPassword,
                Password     = Security.Sha256(rvm.UserPassword),
                LoginIP      = HttpContext.Current.Request.UserHostAddress,
                UserLoginNum = 0,
                Valid        = false,
                lastdate     = DateTime.Now,
                ActiveCode   = Guid.NewGuid().ToString("N")
            };

            this.users.Insert(au);

            this.userDetails.Insert(new UserDetail
            {
                DisplayName = rvm.DisplayName,
                CompanyName = rvm.CompanyName,
                Email       = rvm.Email,
                Address     = rvm.Address,
                Tel         = rvm.Tel,
                UserID      = au.UserID,
            });

            this.usersRole.Insert(new UserRole
            {
                UserID = au.UserID,
                RoleID = 4
            });
            return(sendRegistermail(au.UserName, au.UserID.ToString(), au.ActiveCode, rvm.Email));
        }
Exemplo n.º 10
0
 public ActionResult Index(RegViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Member mb = MemberService.Create(model);
             MemberService.SetLoginCookie(mb);
             //if (mb.MemberType == (int)MemberType.Source)
             //{
             //    return Redirect(Url.Action("openbiz"));
             //}
             return(Redirect(Url.Action("regok")));
         }
         catch (Exception ex)
         {
             LogHelper.WriteLog("用户:" + model.Email + "注册失败!", ex);
             TempData["FormError"] = true;
             return(View(model));
         }
     }
     else
     {
         TempData["FormError"] = true;
         return(View(model));
     }
 }
        public ActionResult Register(string id, string phone)
        {
            var r = new RegViewModel();

            r.id    = id;
            r.phone = phone.Trim().Replace(" ", "");
            return(View(r));
        }
Exemplo n.º 12
0
        public ActionResult Index()
        {
            var model = new RegViewModel();

            ViewBag.Data_MemberType = UIHelper.MemberTypeList;

            return(View(model));
        }
Exemplo n.º 13
0
 public IActionResult Register(RegViewModel register)
 {
     if (ModelState.IsValid)
     {
         return(RedirectToAction("Success"));
     }
     return(View("Index"));
 }
Exemplo n.º 14
0
        private void tbRegNo_GotFocus(object sender, RoutedEventArgs e)
        {
            RegViewModel model = this.DataContext as RegViewModel;

            model.RegNoEnable       = true;
            model.IsDisPlayKeyboard = true;

            tbRegNo.CaretIndex = tbRegNo.Text.Length;
        }
Exemplo n.º 15
0
        public Customers Converter(RegViewModel model)
        {
            Customers newCustomer = new Customers();

            newCustomer.CustomerName          = model.CustomerName;
            newCustomer.Gender                = model.Gender;
            newCustomer.Password              = model.Password;
            newCustomer.CustomerAddress       = model.CustomerAddress;
            newCustomer.ContactInfo.ContactNo = model.ContactNo;
            newCustomer.ContactInfo.Email     = model.Email;
            newCustomer.CityID                = Convert.ToInt32(model.City);
            return(newCustomer);
        }
Exemplo n.º 16
0
        public async Task <ActionResult> Register(RegViewModel model)
        {
            Validation validate = new Validation();

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.CustomerName, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await this.UserManager.AddToRoleAsync(user.Id, "Customer");

                    try
                    {
                        bool added = validate.AddCustomer(Converter(model));
                        if (added == true)
                        {
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            return(Content("Unable to add new customer"));
                        }
                    }
                    catch
                    {
                    }



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

                    return(RedirectToAction("Index", "Home"));
                }
                // var userbyemail = UserManager.FindByEmail("*****@*****.**");
                ViewBag.Name = new SelectList(validate.GetAllValidCities(), "CityID", "CityName");
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 17
0
 public ActionResult Reg(RegViewModel rvm)
 {
     if (ModelState.IsValid)
     {
         var a = this.webservice.reg(rvm);
         if (a == "1")
         {
             return(View("SendEmail", rvm));
         }
         else
         {
             return(View("ErrorEmail", (object)a));
         }
     }
     return(View());
 }
Exemplo n.º 18
0
        public async Task <ActionResult> Reg(RegViewModel rvm)
        {
            if (ModelState.IsValid)
            {
                var a = await UserManage.Reg(rvm);

                if (a.Item1)
                {
                    return(View("SendEmail", rvm));
                }
                else
                {
                    return(View("ErrorEmail", (object)a.Item2));
                }
            }
            return(View());
        }
Exemplo n.º 19
0
 public IActionResult Register(RegViewModel model)
 {
     if (ModelState.IsValid)
     {
         System.Console.WriteLine("YOU GOT TO HERE !!!!!!!");
         User bob = new User
         {
             name     = model.Name,
             password = model.password
         };
         _context.Peeps.Add(bob);
         return(View("success"));
     }
     System.Console.WriteLine("Well, we got to this one isntead");
     ViewBag.errors = ModelState.Values;
     return(View("logreg"));
 }
Exemplo n.º 20
0
        public bool createRegBody(string Email, string FullName, string UserName, string Password, string Resource)
        {
            try
            {
                RestRequest req = commonMethodsApi.generate_request(Resource, "Post");
                req.RequestFormat = DataFormat.Json;
                var param = new RegViewModel {
                    Email = Email, FullName = FullName, UserName = UserName, Password = Password
                };
                req.AddJsonBody(param);

                _scenerioContext.Add("Request", req);
                return(true);
            }
            catch (Exception ex) {
                throw ex;
            }
        }
 public ActionResult Register(RegViewModel model, string returnUrl)
 {
     try
     {
         client = new FireSharp.FirebaseClient(config);
         var data = model;
         data.phone = "+" + model.phone.Replace(" ", "");
         //PushResponse response = client.Push("User/" + data.Id, data);
         data.id = model.id;
         SetResponse setResponse = client.Set("User/" + data.phone, data);
         returnUrl = "/";
         return(this.RedirectToLocal(returnUrl));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(string.Empty, ex.Message);
     }
     return(View());
 }
Exemplo n.º 22
0
        public bool createRegisterBody(string Username, string password, string Email, string FullName)
        {
            try
            {
                RestRequest req   = commonMethodsApi.generate_request("Admin/RegisterAdmin", "Post");
                var         Admin = new RegViewModel {
                    UserName = Username, Password = password, FullName = FullName, Email = Email
                };
                req.AddHeader("Authorization", string.Format("Bearer {0}", _featureContext.Get <string>("token")));
                req.AddJsonBody(Admin);
                _scenerioContext.Add("Request", req);
                return(true);
            }
            catch (Exception e)
            {
                return(false);

                throw e;
            }
        }
Exemplo n.º 23
0
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            string url            = "http://*****:*****@") && txtPassword.Password.Length >= 8)
            {
                RegViewModel regData = new RegViewModel
                {
                    Name      = txtName.Text,
                    UserEmail = txtEmail.Text,
                    Password  = txtPassword.Password
                };

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = JsonConvert.SerializeObject(regData);
                    streamWriter.Write(json);
                }
                try
                {
                    String resultStr = String.Empty;
                    using (HttpWebResponse response =
                               (HttpWebResponse)httpWebRequest.GetResponse())
                    {
                    }
                    Close();
                }
                catch
                {
                    MessageBox.Show("Problem with adding");
                }
            }
            else
            {
                MessageBox.Show("Try again!!!");
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> Register(RegViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "验证未通过");
                return(View(model));
            }

            var userEntity = new UsersEntity();

            userEntity.UserName     = model.UserName;
            userEntity.UserPassword = Md5.EncryptHexString(model.UserPassword);

            bool bFlag = await _UsersService.AddAsync(userEntity);

            if (!bFlag)
            {
                ModelState.AddModelError(string.Empty, "注册失败");
                return(View(model));
            }

            return(RedirectToLocal(returnUrl));
        }
Exemplo n.º 25
0
 public ActionResult RegBiz(RegBizViewModel model)
 {
     if (ModelState.IsValid)
     {
         #region 注册用户并登录
         try
         {
             RegViewModel rm = new RegViewModel()
             {
                 Email      = model.Email,
                 NickName   = model.NickName,
                 Password   = model.Password,
                 Mobile     = model.Mobile,
                 MemberType = 2
             };
             Member mb = MemberService.Create(rm);
             MemberService.SetLoginCookie(mb);
             ProfileViewModel pm = new ProfileViewModel()
             {
                 CityCode = model.CityCode,
                 Borthday = DateTime.Now,
                 NickName = mb.NickName,
                 RealName = model.LinkMan,
                 Sex      = model.Sex
             };
             MemberService.SaveMemberProfile(mb.MemberID, pm);
             ContactViewModel cm = new ContactViewModel()
             {
                 Address = model.Address,
                 Email   = model.Email,
                 Mobile  = model.Mobile,
                 //Phone = model.Phone,
                 Position = model.Position
             };
             MemberService.SaveMemberContact(mb.MemberID, cm);
             CompanyRegViewModel cr = new CompanyRegViewModel()
             {
                 Address     = model.Address,
                 CityCode    = model.CityCode,
                 Description = model.Description,
                 LinkMan     = model.LinkMan,
                 Mobile      = model.Mobile,
                 Name        = model.Name,
                 //Phone = model.Phone,
                 Position = model.Position,
                 Sex      = model.Sex
             };
             CompanyService.SaveBasInfo(mb.MemberID, cr);
             return(Redirect(Url.Action("regauth")));
         }
         catch (Exception ex)
         {
             LogHelper.WriteLog("用户:" + model.Email + "企业注册失败!", ex);
             TempData["FormError"] = true;
             return(View(model));
         }
         #endregion
     }
     else
     {
         TempData["FormError"] = true;
         return(View(model));
     }
 }
Exemplo n.º 26
0
 public ActionResult SendEmail(RegViewModel uvm)
 {
     return(View(uvm));
 }
        public ActionResult Registration(RegViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBagAppointmentList(model.ProducerId);
                return(View(model));
            }

            // если уже есть такой пользователь
            var user = DB.Account.SingleOrDefault(x => x.Login == model.login);

            if (user != null)
            {
                ErrorMessage("Пользователь с указанным email уже зарегистрирован, попробуйте восстановить пароль");
                ViewBagAppointmentList(model.ProducerId);
                return(View(model));
            }

            // если такой компании нет. Компания - это не производитель, это прослойка под производителем
            var company = DB.AccountCompany.SingleOrDefault(x => x.ProducerId == model.ProducerId);

            if (company == null)
            {
                company = new AccountCompany()
                {
                    ProducerId = model.ProducerId, Name = model.ProducerName
                };
                DB.AccountCompany.Add(company);
                DB.SaveChanges();

                string domainName = model.login.Split('@')[1].ToLower();
                var    domain     = new CompanyDomainName()
                {
                    Name = domainName, CompanyId = company.Id
                };
                DB.CompanyDomainName.Add(domain);
                DB.SaveChanges();
            }

            // создали новый аккаунт
            var password = GetRandomPassword();
            var account  = SaveAccount(accountCompany: company, Reg_ViewModel: model, Pass: password);

            var regionCodes = DB.Regions().Select(x => x.Id).ToList();

            foreach (var regionCode in regionCodes)
            {
                account.AccountRegion.Add(new AccountRegion()
                {
                    AccountId = account.Id, RegionId = regionCode
                });
            }

            // добавили аккаунт в группу админов
            var adminGroup = DB.AdminGroup();

            account.AccountGroup.Add(adminGroup);
            account.LastUpdatePermisison = DateTime.Now;
            DB.SaveChanges();

            // отправили письмо о регистрации
            Mails.SendRegistrationMessage(account, password);
            SuccessMessage("Пароль отправлен на ваш email " + account.Login);
            return(Redirect("~"));
        }
        private Account SaveAccount(AccountCompany accountCompany, RegViewModel Reg_ViewModel = null, RegDomainViewModel RegDomain_ViewModel = null, RegNotProducerViewModel RegNotProducer_ViewModel = null, string Pass = null)
        {
            var newAccount = new Account();

            newAccount.EnabledEnum = UserStatus.New;
            newAccount.TypeUser    = (sbyte)TypeUsers.ProducerUser;
            newAccount.CompanyId   = accountCompany.Id;

            // регистрация первого пользователя компании
            if (Reg_ViewModel != null)
            {
                newAccount.Login           = Reg_ViewModel.login;
                newAccount.Password        = Md5HashHelper.GetHash(Pass);
                newAccount.PasswordUpdated = DateTime.Now;
                newAccount.FirstName       = Reg_ViewModel.FirstName;
                newAccount.LastName        = Reg_ViewModel.LastName;
                newAccount.OtherName       = Reg_ViewModel.OtherName;
                newAccount.Name            = Reg_ViewModel.LastName + " " + Reg_ViewModel.FirstName + " " + Reg_ViewModel.OtherName;
                newAccount.Phone           = Reg_ViewModel.PhoneNumber;
                newAccount.AppointmentId   = Reg_ViewModel.AppointmentId;
            }

            // регистрация второго и последующих пользователей производителя
            if (RegDomain_ViewModel != null)
            {
                newAccount.Login           = RegDomain_ViewModel.Mailname + "@" + DB.CompanyDomainName.Single(x => x.Id == RegDomain_ViewModel.EmailDomain).Name;
                newAccount.Password        = Md5HashHelper.GetHash(Pass);
                newAccount.PasswordUpdated = DateTime.Now;
                newAccount.FirstName       = RegDomain_ViewModel.FirstName;
                newAccount.LastName        = RegDomain_ViewModel.LastName;
                newAccount.OtherName       = RegDomain_ViewModel.OtherName;
                newAccount.Name            = RegDomain_ViewModel.LastName + " " + RegDomain_ViewModel.FirstName + " " + RegDomain_ViewModel.OtherName;
                newAccount.Phone           = RegDomain_ViewModel.PhoneNumber;
                newAccount.AppointmentId   = RegDomain_ViewModel.AppointmentId;
            }

            // Если компания в списке отсутствует
            if (RegNotProducer_ViewModel != null)
            {
                // создали новую должность
                var appointment = new AccountAppointment()
                {
                    Name = RegNotProducer_ViewModel.Appointment, GlobalEnabled = false
                };
                DB.Entry(appointment).State = EntityState.Added;
                DB.SaveChanges();

                newAccount.Login         = RegNotProducer_ViewModel.login;
                newAccount.FirstName     = RegNotProducer_ViewModel.FirstName;
                newAccount.LastName      = RegNotProducer_ViewModel.LastName;
                newAccount.OtherName     = RegNotProducer_ViewModel.OtherName;
                newAccount.Name          = RegNotProducer_ViewModel.LastName + " " + RegNotProducer_ViewModel.FirstName + " " + RegNotProducer_ViewModel.OtherName;
                newAccount.Phone         = RegNotProducer_ViewModel.PhoneNumber;
                newAccount.AppointmentId = appointment.Id;
                // особый статус
                newAccount.EnabledEnum = UserStatus.Request;
            }

            DB.Entry(newAccount).State = EntityState.Added;
            DB.SaveChanges();
            return(newAccount);
        }