public void Add(RegisterApp entity)
        {
            _context.RegisterApps.Add(entity);

            // save to db
            _context.SaveChanges();
        }
        public int SaveClientIDandClientSecret(ClientKeys ClientKeys)
        {
            _context.ClientKeys.Add(ClientKeys);

            //
            return(_context.SaveChanges());
        }
Ejemplo n.º 3
0
        public int DeleteGenerateToken(int CompanyID)
        {
            try
            {
                // sometimes (why?) we can have 2 open tokens so SingleOrDefault, meanwhile fix by FirstOrDefault
                var token = _context.TokensManager.Where(c => c.IsDeleted == false).FirstOrDefault(x => x.RegisterAppId == CompanyID);
                if (token != null)
                {
                    token.IsDeleted = true;

                    return(_context.SaveChanges());
                }
                return(1);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 4
0
        public ActionResult Create(ExpandedUserDTO paramExpandedUserDTO)
        {
            try
            {
                if (paramExpandedUserDTO == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                var Email    = paramExpandedUserDTO.Email.Trim();
                var UserName = paramExpandedUserDTO.Email.Trim();
                var Password = paramExpandedUserDTO.Password.Trim();

                if (Email == "")
                {
                    throw new Exception("No Email");
                }

                if (Password == "")
                {
                    throw new Exception("No Password");
                }

                // UserName is LowerCase of the Email
                UserName = Email.ToLower();

                // Create user
                var objNewAdminUser = new ApplicationUser {
                    UserName = UserName, Email = Email
                };
                var AdminUserCreateResult = UserManager.Create(objNewAdminUser, Password);

                if (AdminUserCreateResult.Succeeded == true)
                {
                    string strNewRole = Convert.ToString(Request.Form["Roles"]);

                    // Put user in role
                    if (strNewRole != "0")
                    {
                        UserManager.AddToRole(objNewAdminUser.Id, strNewRole);
                    }

                    // create app to use the arabizi
                    var userId   = objNewAdminUser.Id;
                    var appLimit = Convert.ToInt32(ConfigurationManager.AppSettings["TotalAppCallLimit"]);
                    var app      = new RegisterApp {
                        Name = userId + ".app"
                    };
                    new AppManager().CreateApp(app, userId, false, new RegisterAppConcrete(), new ClientKeysConcrete(), appLimit);

                    // create registered user
                    using (var db = new ArabiziDbContext())
                    {
                        var userguid       = Guid.Parse(userId);
                        var registeredUser = db.RegisterUsers.SingleOrDefault(m => m.UserGuid == userguid);
                        if (registeredUser == null)
                        {
                            db.RegisterUsers.Add(new RegisterUser
                            {
                                UserGuid      = userguid,
                                LastLoginTime = DateTime.Now,
                                Username      = Email,
                                Password      = Password,
                                CreateOn      = DateTime.Now,
                                EmailID       = Email,
                            });
                        }
                        else
                        {
                            registeredUser.LastLoginTime = DateTime.Now;
                        }

                        // commit
                        db.SaveChanges();
                    }

                    return(Redirect("~/Admin"));
                }
                else
                {
                    ViewBag.Roles = GetAllRolesAsSelectList();
                    ModelState.AddModelError(string.Empty, "Error: Failed to create the user. Check password requirements.");
                    return(View(paramExpandedUserDTO));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Roles = GetAllRolesAsSelectList();
                ModelState.AddModelError(string.Empty, "Error: " + ex);
                return(View("Create"));
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Require the user to have a confirmed email before they can log on.
            var user = await UserManager.FindByNameAsync(model.Email);

            if (user != null)
            {
                //
                // string callbackUrl = await SendEmailConfirmationTokenAsync(user);
                if (!await UserManager.IsEmailConfirmedAsync(user.Id))
                {
                    ViewBag.errorMessage = "You must have a confirmed email to log on.";
                    return(View("Error"));
                }
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                goto createDefaultTheme;

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", R.InvalidLoginAttempt);
                return(View(model));
            }

createDefaultTheme:
            // TMP DEV TIME : Create default theme if there is not any one before
            var userIdentity = SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity;
            String userId   = SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();
            var    arabizer = new Arabizer();

            if (arabizer.loaddeserializeM_XTRCTTHEME_DAPPERSQL(userId).Count == 0)
            {
                arabizer.saveserializeM_XTRCTTHEME_EFSQL(new M_XTRCTTHEME
                {
                    ID_XTRCTTHEME = Guid.NewGuid(),
                    CurrentActive = "active",
                    ThemeName     = "Default",
                    UserID        = userId
                });
            }

            // create Default App For Admin (and actually any new user) first time
            if (arabizer.loaddeserializeRegisterApp_DAPPERSQL(userId).Count == 0)
            {
                // create app to use the arabizi
                var appLimit = Convert.ToInt32(ConfigurationManager.AppSettings["TotalAppCallLimit"]);
                var app      = new RegisterApp {
                    Name = userId + ".app"
                };
                new AppManager().CreateApp(app, userId, false, new RegisterAppConcrete(), new ClientKeysConcrete(), appLimit);
            }

            // create registered user
            using (var db = new ArabiziDbContext())
            {
                var userguid       = Guid.Parse(userId);
                var registeredUser = db.RegisterUsers.SingleOrDefault(m => m.UserGuid == userguid);
                if (registeredUser == null)
                {
                    db.RegisterUsers.Add(new RegisterUser
                    {
                        UserGuid      = userguid,
                        LastLoginTime = DateTime.Now,
                        Username      = model.Email,
                        Password      = model.Password,
                        CreateOn      = DateTime.Now,
                        EmailID       = model.Email,
                    });
                }
                else
                {
                    registeredUser.LastLoginTime = DateTime.Now;
                }

                // commit
                db.SaveChanges();
            }

            // log login time
            using (var db = new ArabiziDbContext())
            {
                var userguid       = Guid.Parse(userId);
                var registeredUser = db.RegisterUsers.SingleOrDefault(m => m.UserGuid == userguid);
                if (registeredUser == null)
                {
                    db.RegisterUsers.Add(new RegisterUser
                    {
                        UserGuid      = userguid,
                        LastLoginTime = DateTime.Now,
                        Username      = model.Email,
                        Password      = model.Password,
                        CreateOn      = DateTime.Now,
                        EmailID       = model.Email,
                    });
                }
                else
                {
                    registeredUser.LastLoginTime = DateTime.Now;
                }

                // commit
                db.SaveChanges();
            }

            //
            // return RedirectToAction("Index", "Train");
            // return RedirectToAction("IndexTranslateArabizi", "Train");
            return(RedirectToAction("IndexSplash", "Train"));
        }